home *** CD-ROM | disk | FTP | other *** search
open in:
MacOS 8.1
|
Win98
|
DOS
browse contents |
view JSON data
|
view as text
This file was processed as: LaTeX Document
(document/latex).
Confidence | Program | Detection | Match Type | Support
|
---|
100%
| dexvert
| LaTeX Document (document/latex)
| magic
| Supported |
1%
| dexvert
| Text File (text/txt)
| fallback
| Supported |
100%
| file
| LaTeX document text
| default
| |
99%
| file
| LaTeX document, ASCII text
| default
| |
100%
| TrID
| LaTeX 2e document (with rem)
| default
| |
100%
| checkBytes
| Printable ASCII
| default
| |
100%
| perlTextCheck
| Likely Text (Perl)
| default
| |
100%
| siegfried
| fmt/281 LaTeX (Subdocument)
| default
| |
100%
| gt2
| HTML (Hyper Text Markup Language) Datei
| default
| |
100%
| detectItEasy
| Format: plain text[LF]
| default (weak)
|
|
hex view+--------+-------------------------+-------------------------+--------+--------+
|00000000| 25 20 54 68 69 73 20 69 | 73 20 61 20 6c 61 74 65 |% This i|s a late|
|00000010| 78 20 66 69 6c 65 2e 20 | 49 74 20 63 61 6e 20 61 |x file. |It can a|
|00000020| 6c 73 6f 20 62 65 20 72 | 65 61 64 20 61 73 20 61 |lso be r|ead as a|
|00000030| 20 74 65 78 74 20 66 69 | 6c 65 2e 0a 5c 64 6f 63 | text fi|le..\doc|
|00000040| 75 6d 65 6e 74 73 74 79 | 6c 65 7b 61 72 74 69 63 |umentsty|le{artic|
|00000050| 6c 65 7d 5c 62 65 67 69 | 6e 7b 64 6f 63 75 6d 65 |le}\begi|n{docume|
|00000060| 6e 74 7d 0a 5c 70 61 72 | 69 6e 64 65 6e 74 20 30 |nt}.\par|indent 0|
|00000070| 70 74 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |pt | |
|00000080| 20 20 20 20 25 6e 6f 20 | 69 6e 64 65 6e 74 20 69 | %no |indent i|
|00000090| 6e 20 66 69 72 73 74 20 | 6c 69 6e 65 20 6f 66 20 |n first |line of |
|000000a0| 70 61 72 61 67 72 61 70 | 68 0a 5c 70 61 72 73 6b |paragrap|h.\parsk|
|000000b0| 69 70 20 2e 37 65 6d 20 | 20 20 20 20 20 20 20 20 |ip .7em | |
|000000c0| 20 20 20 20 20 20 20 20 | 20 20 25 76 73 6b 69 70 | | %vskip|
|000000d0| 20 62 65 74 77 65 65 6e | 20 70 61 72 61 67 72 61 | between| paragra|
|000000e0| 70 68 73 0a 5c 74 69 74 | 6c 65 7b 5c 62 66 20 0a |phs.\tit|le{\bf .|
|000000f0| 20 20 20 20 20 20 20 20 | 45 4c 4b 20 45 58 54 45 | |ELK EXTE|
|00000100| 4e 53 49 4f 4e 53 20 54 | 55 54 4f 52 49 41 4c 0a |NSIONS T|UTORIAL.|
|00000110| 7d 0a 5c 61 75 74 68 6f | 72 7b 0a 20 20 20 20 20 |}.\autho|r{. |
|00000120| 20 20 20 4a 2e 50 2e 4c | 65 77 69 73 5c 5c 0a 20 | J.P.L|ewis\\. |
|00000130| 20 20 20 20 20 20 20 4e | 45 43 20 43 5c 26 43 20 | N|EC C\&C |
|00000140| 52 65 73 65 61 72 63 68 | 5c 5c 0a 20 20 20 20 20 |Research|\\. |
|00000150| 20 20 20 7a 69 6c 6c 61 | 40 63 63 72 6c 2e 6e 6a | zilla|@ccrl.nj|
|00000160| 2e 6e 65 63 2e 63 6f 6d | 0a 7d 0a 0a 5c 64 61 74 |.nec.com|.}..\dat|
|00000170| 65 7b 4e 6f 76 65 6d 62 | 65 72 20 31 33 2c 20 31 |e{Novemb|er 13, 1|
|00000180| 39 39 32 20 28 31 29 7d | 0a 0a 5c 6d 61 6b 65 74 |992 (1)}|..\maket|
|00000190| 69 74 6c 65 0a 0a 54 68 | 69 73 20 64 6f 63 75 6d |itle..Th|is docum|
|000001a0| 65 6e 74 20 64 65 73 63 | 72 69 62 65 73 20 73 65 |ent desc|ribes se|
|000001b0| 76 65 72 61 6c 20 65 78 | 74 65 6e 73 69 6f 6e 73 |veral ex|tensions|
|000001c0| 20 74 6f 20 45 6c 6b 20 | 73 63 68 65 6d 65 3a 0a | to Elk |scheme:.|
|000001d0| 5c 62 65 67 69 6e 7b 65 | 6e 75 6d 65 72 61 74 65 |\begin{e|numerate|
|000001e0| 7d 0a 5c 69 74 65 6d 0a | 20 20 20 41 20 66 6f 72 |}.\item.| A for|
|000001f0| 65 69 67 6e 20 66 75 6e | 63 74 69 6f 6e 20 69 6e |eign fun|ction in|
|00000200| 74 65 72 66 61 63 65 2c | 20 63 75 72 72 65 6e 74 |terface,| current|
|00000210| 6c 79 20 61 76 61 69 6c | 61 62 6c 65 20 66 6f 72 |ly avail|able for|
|00000220| 20 53 70 61 72 63 20 61 | 6e 64 20 53 47 49 20 0a | Sparc a|nd SGI .|
|00000230| 20 20 20 6d 61 63 68 69 | 6e 65 73 20 6f 6e 6c 79 | machi|nes only|
|00000240| 2e 20 54 68 65 20 61 75 | 74 68 6f 72 20 63 61 6e |. The au|thor can|
|00000250| 20 70 72 6f 62 61 62 6c | 79 20 70 72 6f 76 69 64 | probabl|y provid|
|00000260| 65 20 73 6f 6d 65 20 68 | 69 6e 74 73 20 6f 6e 20 |e some h|ints on |
|00000270| 70 6f 72 74 69 6e 67 0a | 20 20 20 74 6f 20 6f 74 |porting.| to ot|
|00000280| 68 65 72 20 6d 61 63 68 | 69 6e 65 73 2e 0a 5c 69 |her mach|ines..\i|
|00000290| 74 65 6d 0a 20 20 60 45 | 6c 6b 20 53 68 65 6c 6c |tem. `E|lk Shell|
|000002a0| 27 2c 20 69 2e 65 2c 20 | 61 20 73 65 74 20 6f 66 |', i.e, |a set of|
|000002b0| 20 28 6d 6f 73 74 6c 79 | 20 66 6f 72 65 69 67 6e | (mostly| foreign|
|000002c0| 20 66 75 6e 63 74 69 6f | 6e 29 20 62 69 6e 64 69 | functio|n) bindi|
|000002d0| 6e 67 73 20 74 6f 20 0a | 20 20 20 4f 2f 53 20 72 |ngs to .| O/S r|
|000002e0| 6f 75 74 69 6e 65 73 20 | 77 68 69 63 68 20 70 65 |outines |which pe|
|000002f0| 72 6d 69 74 20 45 6c 6b | 20 74 6f 20 62 65 20 75 |rmit Elk| to be u|
|00000300| 73 65 64 20 61 73 20 61 | 6e 20 65 78 63 65 6c 6c |sed as a|n excell|
|00000310| 65 6e 74 20 73 68 65 6c | 6c 20 0a 20 20 20 70 72 |ent shel|l . pr|
|00000320| 6f 67 72 61 6d 6d 69 6e | 67 20 6c 61 6e 67 75 61 |ogrammin|g langua|
|00000330| 67 65 2e 0a 5c 69 74 65 | 6d 0a 20 20 20 45 6c 6b |ge..\ite|m. Elk|
|00000340| 20 76 65 63 74 6f 72 20 | 65 78 74 65 6e 73 69 6f | vector |extensio|
|00000350| 6e 73 2c 20 6f 72 20 60 | 41 50 4c 20 69 6e 20 53 |ns, or `|APL in S|
|00000360| 63 68 65 6d 65 27 2e 20 | 20 54 68 69 73 20 65 78 |cheme'. | This ex|
|00000370| 74 65 6e 73 69 6f 6e 20 | 70 65 72 6d 69 74 73 0a |tension |permits.|
|00000380| 20 20 20 66 61 69 72 6c | 79 20 65 66 66 69 63 69 | fairl|y effici|
|00000390| 65 6e 74 20 6e 75 6d 65 | 72 69 63 61 6c 20 28 61 |ent nume|rical (a|
|000003a0| 6e 64 20 69 6e 20 70 61 | 72 74 69 63 75 6c 61 72 |nd in pa|rticular|
|000003b0| 20 66 6c 6f 61 74 69 6e | 67 20 70 6f 69 6e 74 29 | floatin|g point)|
|000003c0| 20 63 6f 6d 70 75 74 61 | 74 69 6f 6e 0a 20 20 20 | computa|tion. |
|000003d0| 69 6e 20 53 63 68 65 6d | 65 2c 20 64 65 73 70 69 |in Schem|e, despi|
|000003e0| 74 65 20 74 68 65 20 66 | 61 63 74 20 74 68 61 74 |te the f|act that|
|000003f0| 20 45 6c 6b 20 69 73 20 | 61 6e 20 69 6e 74 65 72 | Elk is |an inter|
|00000400| 70 72 65 74 65 72 2e 0a | 5c 65 6e 64 7b 65 6e 75 |preter..|\end{enu|
|00000410| 6d 65 72 61 74 65 7d 0a | 0a 5c 73 65 63 74 69 6f |merate}.|.\sectio|
|00000420| 6e 7b 45 6c 6b 20 53 68 | 65 6c 6c 7d 0a 0a 5c 73 |n{Elk Sh|ell}..\s|
|00000430| 75 62 73 65 63 74 69 6f | 6e 7b 41 64 76 65 72 74 |ubsectio|n{Advert|
|00000440| 69 73 65 6d 65 6e 74 7d | 0a 0a 54 68 65 20 45 6c |isement}|..The El|
|00000450| 6b 20 53 68 65 6c 6c 20 | 73 79 6e 74 61 78 20 66 |k Shell |syntax f|
|00000460| 6f 72 20 73 69 6d 70 6c | 65 20 73 68 65 6c 6c 20 |or simpl|e shell |
|00000470| 63 6f 6d 6d 61 6e 64 73 | 20 69 73 20 6c 65 73 73 |commands| is less|
|00000480| 20 63 6f 6e 76 65 6e 69 | 65 6e 74 20 74 68 61 6e | conveni|ent than|
|00000490| 20 0a 74 68 61 74 20 6f | 66 20 74 68 65 20 73 68 | .that o|f the sh|
|000004a0| 2c 63 73 68 2c 20 61 6e | 64 20 50 65 72 6c 2e 20 |,csh, an|d Perl. |
|000004b0| 20 54 68 65 20 63 6f 6e | 73 74 72 75 63 74 69 6f | The con|structio|
|000004c0| 6e 20 6f 66 20 63 6f 6d | 70 6c 65 78 20 63 6f 6d |n of com|plex com|
|000004d0| 6d 61 6e 64 73 2c 0a 68 | 6f 77 65 76 65 72 2c 20 |mands,.h|owever, |
|000004e0| 69 73 20 6d 6f 72 65 20 | 63 6f 6e 73 69 73 74 65 |is more |consiste|
|000004f0| 6e 74 2c 20 73 69 6d 70 | 6c 65 72 2c 20 61 6e 64 |nt, simp|ler, and|
|00000500| 20 6d 6f 72 65 20 60 70 | 6f 77 65 72 66 75 6c 27 | more `p|owerful'|
|00000510| 20 74 68 61 6e 20 0a 69 | 6e 20 73 68 65 6c 6c 73 | than .i|n shells|
|00000520| 20 73 75 63 68 20 61 73 | 20 73 68 2c 63 73 68 2c | such as| sh,csh,|
|00000530| 20 61 6e 64 20 50 65 72 | 6c 3b 20 63 6f 6d 70 6c | and Per|l; compl|
|00000540| 65 78 20 63 6f 6d 6d 61 | 6e 64 73 20 61 72 65 20 |ex comma|nds are |
|00000550| 63 6f 6d 70 6f 73 65 64 | 0a 75 73 69 6e 67 20 53 |composed|.using S|
|00000560| 63 68 65 6d 65 27 73 20 | 73 69 6d 70 6c 65 20 72 |cheme's |simple r|
|00000570| 75 6c 65 73 2e 0a 53 68 | 65 6c 6c 20 6c 61 6e 67 |ules..Sh|ell lang|
|00000580| 75 61 67 65 73 20 6f 66 | 74 65 6e 20 68 61 76 65 |uages of|ten have|
|00000590| 20 61 20 60 60 73 79 6e | 74 61 78 20 77 61 6c 6c | a ``syn|tax wall|
|000005a0| 3a 20 0a 65 78 63 65 73 | 73 20 73 79 6e 74 61 78 |: .exces|s syntax|
|000005b0| 20 69 73 20 69 6e 74 72 | 6f 64 75 63 65 64 20 74 | is intr|oduced t|
|000005c0| 6f 20 6d 61 6b 65 20 73 | 69 6d 70 6c 65 20 6f 70 |o make s|imple op|
|000005d0| 65 72 61 74 69 6f 6e 73 | 20 63 6f 6e 76 65 6e 69 |erations| conveni|
|000005e0| 65 6e 74 2c 20 0a 62 75 | 74 20 74 68 65 20 73 79 |ent, .bu|t the sy|
|000005f0| 6e 74 61 78 20 64 6f 65 | 73 20 6e 6f 74 20 63 6f |ntax doe|s not co|
|00000600| 6d 62 69 6e 65 20 65 61 | 73 69 6c 79 2d 2d 0a 63 |mbine ea|sily--.c|
|00000610| 6f 6d 70 6f 73 69 6e 67 | 20 63 6f 6d 70 6c 65 78 |omposing| complex|
|00000620| 20 6f 70 65 72 61 74 69 | 6f 6e 73 20 72 65 71 75 | operati|ons requ|
|00000630| 69 72 65 73 20 63 6f 6e | 66 75 73 69 6e 67 20 63 |ires con|fusing c|
|00000640| 6f 6d 62 69 6e 61 74 69 | 6f 6e 73 0a 6f 66 20 65 |ombinati|ons.of e|
|00000650| 73 63 61 70 69 6e 67 2c | 20 64 65 72 65 66 65 72 |scaping,| derefer|
|00000660| 65 6e 63 69 6e 67 2c 20 | 71 75 6f 74 69 6e 67 2c |encing, |quoting,|
|00000670| 20 61 6e 64 20 6f 74 68 | 65 72 20 6f 70 65 72 61 | and oth|er opera|
|00000680| 74 6f 72 73 2e 0a 45 78 | 70 72 65 73 73 69 6f 6e |tors..Ex|pression|
|00000690| 73 20 62 65 67 69 6e 20 | 74 6f 20 6c 6f 6f 6b 20 |s begin |to look |
|000006a0| 73 6f 6d 65 74 68 69 6e | 67 20 6c 69 6b 65 0a 5c |somethin|g like.\|
|000006b0| 62 65 67 69 6e 7b 76 65 | 72 62 61 74 69 6d 7d 0a |begin{ve|rbatim}.|
|000006c0| 20 20 20 20 22 27 5c 24 | 5c 5c 7b 41 42 43 7d 27 | "'\$|\\{ABC}'|
|000006d0| 22 0a 5c 65 6e 64 7b 76 | 65 72 62 61 74 69 6d 7d |".\end{v|erbatim}|
|000006e0| 0a 0a 53 63 68 65 6d 65 | 20 68 61 73 20 6d 69 6e |..Scheme| has min|
|000006f0| 69 6d 61 6c 20 73 79 6e | 74 61 78 20 61 6e 64 20 |imal syn|tax and |
|00000700| 61 20 73 69 6d 70 6c 65 | 20 61 6e 64 20 63 6f 6e |a simple| and con|
|00000710| 73 69 73 74 65 6e 74 20 | 6d 65 61 6e 73 20 6f 66 |sistent |means of|
|00000720| 20 63 6f 6d 70 6f 73 69 | 6e 67 20 0a 66 75 6e 63 | composi|ng .func|
|00000730| 74 69 6f 6e 73 2c 20 77 | 69 74 68 20 74 68 65 20 |tions, w|ith the |
|00000740| 72 65 73 75 6c 74 20 74 | 68 61 74 20 73 69 6d 70 |result t|hat simp|
|00000750| 6c 65 20 63 6f 6e 73 74 | 72 75 63 74 73 20 61 72 |le const|ructs ar|
|00000760| 65 20 70 65 72 68 61 70 | 73 20 6d 6f 72 65 20 76 |e perhap|s more v|
|00000770| 65 72 62 6f 73 65 2c 0a | 62 75 74 20 63 6f 6d 70 |erbose,.|but comp|
|00000780| 6c 65 78 20 63 6f 6e 73 | 74 72 75 63 74 73 20 61 |lex cons|tructs a|
|00000790| 72 65 20 6d 75 63 68 20 | 73 69 6d 70 6c 65 72 2e |re much |simpler.|
|000007a0| 0a 49 6d 70 6f 72 74 61 | 6e 74 20 6f 70 65 72 61 |.Importa|nt opera|
|000007b0| 74 69 6f 6e 73 20 61 72 | 65 20 65 61 73 69 6c 79 |tions ar|e easily|
|000007c0| 20 61 62 73 74 72 61 63 | 74 65 64 20 61 6e 64 20 | abstrac|ted and |
|000007d0| 73 61 76 65 64 20 69 6e | 20 0a 6c 69 62 72 61 72 |saved in| .librar|
|000007e0| 69 65 73 20 66 6f 72 20 | 6c 61 74 65 72 20 72 65 |ies for |later re|
|000007f0| 75 73 65 2e 0a 53 63 68 | 65 6d 65 20 70 72 6f 76 |use..Sch|eme prov|
|00000800| 69 64 65 73 20 63 6f 6e | 73 69 64 65 72 61 62 6c |ides con|siderabl|
|00000810| 65 20 60 63 6f 67 6e 69 | 74 69 76 65 20 65 63 6f |e `cogni|tive eco|
|00000820| 6e 6f 6d 79 27 2c 20 0a | 73 69 6e 63 65 20 77 69 |nomy', .|since wi|
|00000830| 74 68 20 73 6f 6d 65 20 | 65 66 66 6f 72 74 20 69 |th some |effort i|
|00000840| 74 20 63 61 6e 20 62 65 | 20 75 73 65 64 20 66 6f |t can be| used fo|
|00000850| 72 20 6d 61 6e 79 20 6f | 66 20 74 68 65 0a 74 61 |r many o|f the.ta|
|00000860| 73 6b 73 20 61 64 64 72 | 65 73 73 65 64 20 62 79 |sks addr|essed by|
|00000870| 20 73 65 70 61 72 61 74 | 65 20 61 6e 64 20 73 79 | separat|e and sy|
|00000880| 6e 74 61 63 74 69 63 61 | 6c 6c 79 20 63 6f 6e 66 |ntactica|lly conf|
|00000890| 75 73 69 6e 67 20 74 6f | 6f 6c 73 20 73 75 63 68 |using to|ols such|
|000008a0| 20 61 73 0a 73 68 2c 63 | 73 68 2c 50 65 72 6c 2c | as.sh,c|sh,Perl,|
|000008b0| 61 77 6b 2c 20 61 6e 64 | 20 66 69 6e 64 2e 0a 0a |awk, and| find...|
|000008c0| 54 68 65 20 66 6f 6c 6c | 6f 77 69 6e 67 20 69 73 |The foll|owing is|
|000008d0| 20 61 6e 20 65 78 61 6d | 70 6c 65 20 6f 66 20 61 | an exam|ple of a|
|000008e0| 20 73 75 62 72 6f 75 74 | 69 6e 65 20 69 6e 20 50 | subrout|ine in P|
|000008f0| 65 72 6c 3a 0a 5c 62 65 | 67 69 6e 7b 76 65 72 62 |erl:.\be|gin{verb|
|00000900| 61 74 69 6d 7d 0a 20 20 | 20 20 73 75 62 20 61 72 |atim}. | sub ar|
|00000910| 72 61 79 61 64 64 20 7b | 0a 20 20 20 20 20 20 6c |rayadd {|. l|
|00000920| 6f 63 61 6c 28 2a 61 2c | 20 2a 62 29 20 3d 20 40 |ocal(*a,| *b) = @|
|00000930| 5f 3b 0a 20 20 20 20 20 | 20 6c 6f 63 61 6c 28 24 |_;. | local($|
|00000940| 6d 61 78 29 20 3d 20 24 | 23 61 20 3e 20 24 23 62 |max) = $|#a > $#b|
|00000950| 20 3f 20 24 23 61 20 3a | 20 24 23 62 3b 0a 20 20 | ? $#a :| $#b;. |
|00000960| 20 20 20 20 6c 6f 63 61 | 6c 28 40 73 75 6d 29 3b | loca|l(@sum);|
|00000970| 0a 20 20 20 20 20 20 66 | 6f 72 20 28 6c 6f 63 61 |. f|or (loca|
|00000980| 6c 28 24 69 29 20 3d 20 | 30 3b 20 24 69 20 3c 3d |l($i) = |0; $i <=|
|00000990| 20 24 6d 61 78 3b 20 24 | 69 2b 2b 29 20 7b 0a 20 | $max; $|i++) {. |
|000009a0| 20 20 20 20 20 20 20 24 | 73 75 6d 5b 24 69 5d 20 | $|sum[$i] |
|000009b0| 3d 20 24 61 5b 24 69 5d | 20 2b 20 24 62 5b 24 69 |= $a[$i]| + $b[$i|
|000009c0| 5d 3b 0a 20 20 20 20 20 | 20 7d 0a 20 20 20 20 20 |];. | }. |
|000009d0| 20 40 73 75 6d 3b 0a 20 | 20 20 20 7d 0a 20 20 20 | @sum;. | }. |
|000009e0| 20 40 66 6f 6f 20 3d 20 | 28 31 2c 32 2c 33 29 3b | @foo = |(1,2,3);|
|000009f0| 0a 20 20 20 20 40 62 61 | 72 20 3d 20 28 31 30 2c |. @ba|r = (10,|
|00000a00| 32 30 2c 33 30 29 3b 0a | 20 20 20 20 40 74 6f 74 |20,30);.| @tot|
|00000a10| 61 6c 73 20 3d 20 26 61 | 72 72 61 79 61 64 64 28 |als = &a|rrayadd(|
|00000a20| 2a 66 6f 6f 2c 20 2a 62 | 61 72 29 3b 0a 5c 65 6e |*foo, *b|ar);.\en|
|00000a30| 64 7b 76 65 72 62 61 74 | 69 6d 7d 0a 54 68 65 20 |d{verbat|im}.The |
|00000a40| 50 65 72 6c 20 63 6f 64 | 65 20 68 61 73 20 74 68 |Perl cod|e has th|
|00000a50| 65 20 74 79 70 69 63 61 | 6c 20 60 60 6c 69 74 74 |e typica|l ``litt|
|00000a60| 6c 65 20 6c 61 6e 67 75 | 61 67 65 27 27 20 73 79 |le langu|age'' sy|
|00000a70| 6d 70 74 6f 6d 20 6f 66 | 0a 65 78 63 65 73 73 69 |mptom of|.excessi|
|00000a80| 76 65 20 73 79 6e 74 61 | 78 2e 20 20 54 68 69 73 |ve synta|x. This|
|00000a90| 20 65 78 61 6d 70 6c 65 | 20 72 65 71 75 69 72 65 | example| require|
|00000aa0| 73 20 74 68 65 20 63 68 | 61 72 61 63 74 65 72 73 |s the ch|aracters|
|00000ab0| 0a 7b 5c 74 74 20 2a 2c | 5c 24 2c 5c 23 2c 40 2c |.{\tt *,|\$,\#,@,|
|00000ac0| 5c 26 7d 20 61 73 20 77 | 65 6c 6c 20 61 73 20 70 |\&} as w|ell as p|
|00000ad0| 61 72 65 6e 74 68 65 73 | 65 73 2c 20 62 72 61 63 |arenthes|es, brac|
|00000ae0| 6b 65 74 73 20 61 6e 64 | 20 63 75 72 6c 79 20 62 |kets and| curly b|
|00000af0| 72 61 63 65 73 2e 0a 0a | 54 68 65 20 63 6f 72 72 |races...|The corr|
|00000b00| 65 73 70 6f 6e 64 69 6e | 67 20 53 63 68 65 6d 65 |espondin|g Scheme|
|00000b10| 20 69 73 3a 0a 5c 62 65 | 67 69 6e 7b 76 65 72 62 | is:.\be|gin{verb|
|00000b20| 61 74 69 6d 7d 0a 20 20 | 20 20 28 64 65 66 69 6e |atim}. | (defin|
|00000b30| 65 20 28 61 72 72 61 79 | 61 64 64 20 61 20 62 29 |e (array|add a b)|
|00000b40| 20 20 20 28 6d 61 70 20 | 2b 20 61 20 62 29 29 0a | (map |+ a b)).|
|00000b50| 0a 20 20 20 20 28 64 65 | 66 69 6e 65 20 66 6f 6f |. (de|fine foo|
|00000b60| 20 27 28 31 20 32 20 33 | 29 29 0a 20 20 20 20 28 | '(1 2 3|)). (|
|00000b70| 64 65 66 69 6e 65 20 62 | 61 72 20 27 28 31 30 20 |define b|ar '(10 |
|00000b80| 32 30 20 33 30 29 29 0a | 20 20 20 20 28 64 65 66 |20 30)).| (def|
|00000b90| 69 6e 65 20 74 6f 74 61 | 6c 73 20 28 61 72 72 61 |ine tota|ls (arra|
|00000ba0| 79 61 64 64 20 66 6f 6f | 20 62 61 72 29 29 0a 5c |yadd foo| bar)).\|
|00000bb0| 65 6e 64 7b 76 65 72 62 | 61 74 69 6d 7d 0a 0a 5c |end{verb|atim}..\|
|00000bc0| 73 75 62 73 65 63 74 69 | 6f 6e 7b 43 6f 6e 73 74 |subsecti|on{Const|
|00000bd0| 72 75 63 74 69 6e 67 20 | 61 6e 20 45 6c 6b 20 53 |ructing |an Elk S|
|00000be0| 68 65 6c 6c 7d 0a 0a 41 | 6e 20 65 6c 6b 20 73 68 |hell}..A|n elk sh|
|00000bf0| 65 6c 6c 20 66 69 6c 65 | 20 62 65 67 69 6e 73 20 |ell file| begins |
|00000c00| 77 69 74 68 20 61 6e 20 | 69 6e 74 65 72 70 72 65 |with an |interpre|
|00000c10| 74 65 72 20 70 61 74 68 | 20 73 75 63 68 20 61 73 |ter path| such as|
|00000c20| 0a 5c 62 65 67 69 6e 7b | 76 65 72 62 61 74 69 6d |.\begin{|verbatim|
|00000c30| 7d 0a 20 20 20 20 23 21 | 20 2f 75 73 72 2f 6c 6f |}. #!| /usr/lo|
|00000c40| 63 61 6c 2f 62 69 6e 2f | 65 6c 6b 0a 5c 65 6e 64 |cal/bin/|elk.\end|
|00000c50| 7b 76 65 72 62 61 74 69 | 6d 7d 0a 28 45 6c 6b 20 |{verbati|m}.(Elk |
|00000c60| 69 67 6e 6f 72 65 73 20 | 74 68 69 73 20 6c 69 6e |ignores |this lin|
|00000c70| 65 29 3b 0a 74 68 65 20 | 72 65 6d 61 69 6e 64 65 |e);.the |remainde|
|00000c80| 72 20 6f 66 20 74 68 65 | 20 73 68 65 6c 6c 20 66 |r of the| shell f|
|00000c90| 69 6c 65 20 63 6f 6e 74 | 61 69 6e 73 20 53 63 68 |ile cont|ains Sch|
|00000ca0| 65 6d 65 20 66 75 6e 63 | 74 69 6f 6e 20 63 61 6c |eme func|tion cal|
|00000cb0| 6c 73 2e 0a 0a 54 68 65 | 20 45 6c 6b 20 63 61 6c |ls...The| Elk cal|
|00000cc0| 6c 0a 5c 62 65 67 69 6e | 7b 76 65 72 62 61 74 69 |l.\begin|{verbati|
|00000cd0| 6d 7d 0a 20 20 20 20 28 | 61 70 72 6f 70 6f 73 20 |m}. (|apropos |
|00000ce0| 22 6f 73 2d 22 29 20 0a | 5c 65 6e 64 7b 76 65 72 |"os-") .|\end{ver|
|00000cf0| 62 61 74 69 6d 7d 0a 70 | 72 69 6e 74 73 20 61 20 |batim}.p|rints a |
|00000d00| 6c 69 73 74 20 6f 66 20 | 74 68 65 20 70 72 65 2d |list of |the pre-|
|00000d10| 6c 69 6e 6b 65 64 20 73 | 68 65 6c 6c 2d 72 65 6c |linked s|hell-rel|
|00000d20| 61 74 65 64 20 66 75 6e | 63 74 69 6f 6e 73 2e 0a |ated fun|ctions..|
|00000d30| 4d 61 6e 79 20 6f 66 20 | 74 68 65 73 65 20 66 75 |Many of |these fu|
|00000d40| 6e 63 74 69 6f 6e 73 20 | 61 72 65 20 73 69 6d 70 |nctions |are simp|
|00000d50| 6c 79 20 74 68 65 20 63 | 6f 72 72 65 73 70 6f 6e |ly the c|orrespon|
|00000d60| 64 69 6e 67 20 43 20 6c | 69 62 72 61 72 79 20 66 |ding C l|ibrary f|
|00000d70| 75 6e 63 74 69 6f 6e 0a | 65 78 70 6f 72 74 65 64 |unction.|exported|
|00000d80| 20 74 6f 20 45 6c 6b 2e | 20 20 46 6f 72 20 65 78 | to Elk.| For ex|
|00000d90| 61 6d 70 6c 65 2c 20 45 | 6c 6b 20 73 68 65 6c 6c |ample, E|lk shell|
|00000da0| 73 20 63 61 6e 20 72 65 | 61 64 20 61 6e 64 20 77 |s can re|ad and w|
|00000db0| 72 69 74 65 0a 62 69 6e | 61 72 79 20 64 61 74 61 |rite.bin|ary data|
|00000dc0| 20 75 73 69 6e 67 20 7b | 5c 74 74 20 6f 73 2d 66 | using {|\tt os-f|
|00000dd0| 6f 70 65 6e 2c 20 6f 73 | 2d 66 72 65 61 64 2c 20 |open, os|-fread, |
|00000de0| 6f 73 2d 66 77 72 69 74 | 65 2c 20 6f 73 2d 66 63 |os-fwrit|e, os-fc|
|00000df0| 6c 6f 73 65 7d 2e 0a 4f | 74 68 65 72 20 73 68 65 |lose}..O|ther she|
|00000e00| 6c 6c 2d 72 65 6c 61 74 | 65 64 20 66 75 6e 63 74 |ll-relat|ed funct|
|00000e10| 69 6f 6e 73 20 61 72 65 | 20 77 72 69 74 74 65 6e |ions are| written|
|00000e20| 20 73 70 65 63 69 66 69 | 63 61 6c 6c 79 20 66 6f | specifi|cally fo|
|00000e30| 72 20 73 63 68 65 6d 65 | 2e 0a 46 6f 72 20 65 78 |r scheme|..For ex|
|00000e40| 61 6d 70 6c 65 2c 20 7b | 5c 74 74 20 6f 73 2d 67 |ample, {|\tt os-g|
|00000e50| 6c 6f 62 7d 0a 72 65 74 | 75 72 6e 73 20 61 20 6c |lob}.ret|urns a l|
|00000e60| 69 73 74 20 6f 66 20 74 | 68 65 20 66 69 6c 65 6e |ist of t|he filen|
|00000e70| 61 6d 65 73 20 6d 61 74 | 63 68 69 6e 67 20 74 68 |ames mat|ching th|
|00000e80| 65 20 73 70 65 63 69 66 | 69 65 64 20 70 61 74 74 |e specif|ied patt|
|00000e90| 65 72 6e 2c 0a 75 73 69 | 6e 67 20 61 20 73 68 65 |ern,.usi|ng a she|
|00000ea0| 6c 6c 2d 6c 69 6b 65 20 | 6d 61 74 63 68 3a 0a 5c |ll-like |match:.\|
|00000eb0| 62 65 67 69 6e 7b 76 65 | 72 62 61 74 69 6d 7d 0a |begin{ve|rbatim}.|
|00000ec0| 20 20 20 20 28 6f 73 2d | 67 6c 6f 62 20 22 2a 2e | (os-|glob "*.|
|00000ed0| 68 22 29 20 20 3d 3e 20 | 28 22 73 63 68 65 6d 65 |h") => |("scheme|
|00000ee0| 2e 68 22 20 22 6f 62 6a | 65 63 74 2e 68 22 29 0a |.h" "obj|ect.h").|
|00000ef0| 5c 65 6e 64 7b 76 65 72 | 62 61 74 69 6d 7d 0a 47 |\end{ver|batim}.G|
|00000f00| 6c 6f 62 20 77 61 73 20 | 74 68 65 20 6e 61 6d 65 |lob was |the name|
|00000f10| 20 6f 66 20 61 6e 20 6f | 6c 64 20 6e 61 6d 65 20 | of an o|ld name |
|00000f20| 6d 61 74 63 68 69 6e 67 | 20 72 6f 75 74 69 6e 65 |matching| routine|
|00000f30| 2e 20 59 6f 75 20 63 61 | 6e 20 6f 66 0a 63 6f 75 |. You ca|n of.cou|
|00000f40| 72 73 65 20 72 65 6e 61 | 6d 65 20 66 75 6e 63 74 |rse rena|me funct|
|00000f50| 69 6f 6e 73 20 69 6e 20 | 79 6f 75 72 20 45 6c 6b |ions in |your Elk|
|00000f60| 20 73 74 61 72 74 75 70 | 20 69 66 20 79 6f 75 20 | startup| if you |
|00000f70| 77 69 73 68 2c 20 65 2e | 67 2e 2c 0a 5c 62 65 67 |wish, e.|g.,.\beg|
|00000f80| 69 6e 7b 76 65 72 62 61 | 74 69 6d 7d 0a 20 20 20 |in{verba|tim}. |
|00000f90| 20 28 64 65 66 69 6e 65 | 20 6f 73 2d 66 69 6c 65 | (define| os-file|
|00000fa0| 2a 20 6f 73 2d 67 6c 6f | 62 29 0a 5c 65 6e 64 7b |* os-glo|b).\end{|
|00000fb0| 76 65 72 62 61 74 69 6d | 7d 0a 0a 54 68 65 20 73 |verbatim|}..The s|
|00000fc0| 68 65 6c 6c 20 66 75 6e | 63 74 69 6f 6e 73 20 6f |hell fun|ctions o|
|00000fd0| 73 2d 62 73 68 20 61 6e | 64 20 6f 73 2d 63 73 68 |s-bsh an|d os-csh|
|00000fe0| 20 65 78 65 63 75 74 65 | 20 61 20 63 6f 6d 6d 61 | execute| a comma|
|00000ff0| 6e 64 20 73 74 72 69 6e | 67 0a 75 73 69 6e 67 20 |nd strin|g.using |
|00001000| 74 68 65 20 42 6f 75 72 | 6e 65 2d 20 61 6e 64 20 |the Bour|ne- and |
|00001010| 43 2d 73 68 65 6c 6c 73 | 20 72 65 73 70 65 63 74 |C-shells| respect|
|00001020| 69 76 65 6c 79 2c 20 0a | 61 6e 64 20 72 65 74 75 |ively, .|and retu|
|00001030| 72 6e 20 74 68 65 20 65 | 78 69 74 20 73 74 61 74 |rn the e|xit stat|
|00001040| 75 73 20 6f 66 20 74 68 | 65 20 63 6f 6d 6d 61 6e |us of th|e comman|
|00001050| 64 2e 0a 6f 73 2d 62 73 | 68 20 61 6e 64 20 6f 73 |d..os-bs|h and os|
|00001060| 2d 63 73 68 20 61 72 65 | 20 69 6e 63 6f 6e 76 65 |-csh are| inconve|
|00001070| 6e 69 65 6e 74 20 70 72 | 69 6d 69 74 69 76 65 73 |nient pr|imitives|
|00001080| 3b 20 61 20 73 74 72 69 | 6e 67 20 72 65 70 72 65 |; a stri|ng repre|
|00001090| 73 65 6e 74 61 74 69 6f | 6e 0a 6f 66 20 65 61 63 |sentatio|n.of eac|
|000010a0| 68 20 63 6f 6d 6d 61 6e | 64 20 61 6e 64 20 69 74 |h comman|d and it|
|000010b0| 73 20 61 72 67 75 6d 65 | 6e 74 73 20 6d 75 73 74 |s argume|nts must|
|000010c0| 20 62 65 20 61 73 73 65 | 6d 62 6c 65 64 2e 0a 0a | be asse|mbled...|
|000010d0| 4f 74 68 65 72 20 6d 6f | 72 65 20 63 6f 6e 76 65 |Other mo|re conve|
|000010e0| 6e 69 65 6e 74 20 66 75 | 6e 63 74 69 6f 6e 73 20 |nient fu|nctions |
|000010f0| 63 61 6e 20 62 65 20 62 | 75 69 6c 74 20 75 73 69 |can be b|uilt usi|
|00001100| 6e 67 20 74 68 65 73 65 | 20 70 72 69 6d 69 74 69 |ng these| primiti|
|00001110| 76 65 73 2c 20 68 6f 77 | 65 76 65 72 2e 0a 54 68 |ves, how|ever..Th|
|00001120| 65 20 6c 69 62 72 61 72 | 79 20 66 69 6c 65 20 73 |e librar|y file s|
|00001130| 63 6d 2f 73 68 65 6c 6c | 2e 65 20 69 6e 63 6c 75 |cm/shell|.e inclu|
|00001140| 64 65 73 20 73 65 76 65 | 72 61 6c 20 70 6f 73 73 |des seve|ral poss|
|00001150| 69 62 6c 65 20 61 70 70 | 72 6f 61 63 68 65 73 0a |ible app|roaches.|
|00001160| 74 6f 20 61 20 6d 6f 72 | 65 20 63 6f 6e 76 65 6e |to a mor|e conven|
|00001170| 69 65 6e 74 20 73 68 65 | 6c 6c 20 73 79 6e 74 61 |ient she|ll synta|
|00001180| 78 2e 20 20 7b 5c 74 74 | 20 64 65 63 6c 61 72 65 |x. {\tt| declare|
|00001190| 2d 73 68 65 6c 6c 20 7d | 20 69 73 20 6f 6e 65 20 |-shell }| is one |
|000011a0| 61 70 70 72 6f 61 63 68 | 0a 69 6e 20 77 68 69 63 |approach|.in whic|
|000011b0| 68 20 74 68 65 20 73 68 | 65 6c 6c 20 63 6f 6d 6d |h the sh|ell comm|
|000011c0| 61 6e 64 20 61 70 70 65 | 61 72 73 20 61 73 20 61 |and appe|ars as a|
|000011d0| 20 73 63 68 65 6d 65 20 | 66 75 6e 63 74 69 6f 6e | scheme |function|
|000011e0| 2c 20 77 68 69 6c 65 0a | 74 68 65 20 63 6f 6d 6d |, while.|the comm|
|000011f0| 61 6e 64 20 61 72 67 75 | 6d 65 6e 74 73 20 61 72 |and argu|ments ar|
|00001200| 65 20 73 63 68 65 6d 65 | 20 66 75 6e 63 74 69 6f |e scheme| functio|
|00001210| 6e 20 61 72 67 75 6d 65 | 6e 74 73 20 77 68 69 63 |n argume|nts whic|
|00001220| 68 20 73 68 6f 75 6c 64 | 20 65 76 61 6c 75 61 74 |h should| evaluat|
|00001230| 65 0a 74 6f 20 73 74 72 | 69 6e 67 73 2e 0a 45 78 |e.to str|ings..Ex|
|00001240| 61 6d 70 6c 65 73 20 6f | 66 20 63 61 6c 6c 69 6e |amples o|f callin|
|00001250| 67 20 6c 73 3a 0a 5c 62 | 65 67 69 6e 7b 76 65 72 |g ls:.\b|egin{ver|
|00001260| 62 61 74 69 6d 7d 0a 20 | 20 20 20 28 6f 73 2d 63 |batim}. | (os-c|
|00001270| 73 68 20 22 6c 73 20 2f | 65 74 63 22 29 20 20 20 |sh "ls /|etc") |
|00001280| 20 20 20 20 20 20 20 3b | 20 70 72 69 6d 69 74 69 | ;| primiti|
|00001290| 76 65 20 77 61 79 0a 0a | 20 20 20 20 28 6c 6f 61 |ve way..| (loa|
|000012a0| 64 20 22 73 68 65 6c 6c | 2e 65 22 29 0a 20 20 20 |d "shell|.e"). |
|000012b0| 20 28 64 65 63 6c 61 72 | 65 2d 73 68 65 6c 6c 20 | (declar|e-shell |
|000012c0| 6c 73 29 20 0a 20 20 20 | 0a 20 20 20 20 28 6c 73 |ls) . |. (ls|
|000012d0| 20 22 2f 65 74 63 22 29 | 0a 20 20 20 20 28 6c 73 | "/etc")|. (ls|
|000012e0| 20 28 6f 73 2d 67 65 74 | 65 6e 76 20 22 48 4f 4d | (os-get|env "HOM|
|000012f0| 45 22 29 29 0a 20 20 20 | 20 28 64 65 66 69 6e 65 |E")). | (define|
|00001300| 20 24 65 6c 6b 64 69 72 | 20 28 73 74 72 69 6e 67 | $elkdir| (string|
|00001310| 2d 61 70 70 65 6e 64 20 | 28 6f 73 2d 67 65 74 65 |-append |(os-gete|
|00001320| 6e 76 20 22 48 4f 4d 45 | 22 29 20 22 2f 65 6c 6b |nv "HOME|") "/elk|
|00001330| 22 29 29 0a 20 20 20 20 | 28 6c 73 20 24 65 6c 6b |")). |(ls $elk|
|00001340| 64 69 72 29 0a 0a 20 20 | 20 20 28 64 6f 6c 69 73 |dir).. | (dolis|
|00001350| 74 20 28 24 66 69 6c 65 | 20 28 6f 73 2d 67 6c 6f |t ($file| (os-glo|
|00001360| 62 20 22 2a 2e 63 22 29 | 29 0a 20 20 20 20 20 20 |b "*.c")|). |
|00001370| 20 20 28 6c 73 20 22 2d | 6c 22 20 24 69 29 29 20 | (ls "-|l" $i)) |
|00001380| 20 20 20 20 20 20 20 20 | 20 20 3b 20 64 6f 20 60 | | ; do `|
|00001390| 6c 73 20 2d 6c 27 20 6f | 6e 20 2a 2e 63 0a 5c 65 |ls -l' o|n *.c.\e|
|000013a0| 6e 64 7b 76 65 72 62 61 | 74 69 6d 7d 0a 0a 5c 73 |nd{verba|tim}..\s|
|000013b0| 75 62 73 65 63 74 69 6f | 6e 7b 53 68 65 6c 6c 20 |ubsectio|n{Shell |
|000013c0| 45 78 61 6d 70 6c 65 73 | 7d 0a 53 65 76 65 72 61 |Examples|}.Severa|
|000013d0| 6c 20 65 78 61 6d 70 6c | 65 73 20 6f 66 20 73 6d |l exampl|es of sm|
|000013e0| 61 6c 6c 20 45 6c 6b 20 | 53 68 65 6c 6c 20 66 69 |all Elk |Shell fi|
|000013f0| 6c 65 73 20 77 69 6c 6c | 20 62 65 20 67 69 76 65 |les will| be give|
|00001400| 6e 2e 0a 0a 5c 73 75 62 | 73 65 63 74 69 6f 6e 7b |n...\sub|section{|
|00001410| 45 78 61 6d 70 6c 65 20 | 2d 20 44 65 6c 65 74 65 |Example |- Delete|
|00001420| 20 45 6d 70 74 79 20 46 | 69 6c 65 73 7d 0a 5c 62 | Empty F|iles}.\b|
|00001430| 65 67 69 6e 7b 76 65 72 | 62 61 74 69 6d 7d 0a 20 |egin{ver|batim}. |
|00001440| 20 28 64 65 66 69 6e 65 | 20 28 64 65 6c 65 74 65 | (define| (delete|
|00001450| 2d 69 66 2d 65 6d 70 74 | 79 20 66 69 6c 65 29 20 |-if-empt|y file) |
|00001460| 0a 20 20 20 20 28 69 66 | 20 28 65 71 76 3f 20 28 |. (if| (eqv? (|
|00001470| 6f 73 2d 66 69 6c 65 73 | 69 7a 65 20 66 69 6c 65 |os-files|ize file|
|00001480| 29 20 30 29 0a 20 20 20 | 20 20 20 28 6f 73 2d 64 |) 0). | (os-d|
|00001490| 65 6c 65 74 65 2d 66 69 | 6c 65 20 66 69 6c 65 29 |elete-fi|le file)|
|000014a0| 29 29 0a 20 20 20 20 0a | 20 20 28 6d 61 70 20 64 |)). .| (map d|
|000014b0| 65 6c 65 74 65 2d 69 66 | 2d 65 6d 70 74 79 20 28 |elete-if|-empty (|
|000014c0| 6f 73 2d 67 6c 6f 62 20 | 22 2a 2e 2a 22 29 29 0a |os-glob |"*.*")).|
|000014d0| 5c 65 6e 64 7b 76 65 72 | 62 61 74 69 6d 7d 0a 0a |\end{ver|batim}..|
|000014e0| 0a 5c 73 75 62 73 65 63 | 74 69 6f 6e 7b 45 78 61 |.\subsec|tion{Exa|
|000014f0| 6d 70 6c 65 20 2d 20 64 | 69 66 66 64 69 72 7d 0a |mple - d|iffdir}.|
|00001500| 0a 41 20 73 68 65 6c 6c | 20 74 6f 20 63 6f 6d 70 |.A shell| to comp|
|00001510| 61 72 65 20 73 65 6c 65 | 63 74 65 64 20 66 69 6c |are sele|cted fil|
|00001520| 65 73 20 61 67 61 69 6e | 73 74 20 73 69 6d 69 6c |es again|st simil|
|00001530| 61 72 6c 79 20 6e 61 6d | 65 64 20 66 69 6c 65 73 |arly nam|ed files|
|00001540| 0a 69 6e 20 61 6e 6f 74 | 68 65 72 20 64 69 72 65 |.in anot|her dire|
|00001550| 63 74 6f 72 79 3a 0a 5c | 62 65 67 69 6e 7b 76 65 |ctory:.\|begin{ve|
|00001560| 72 62 61 74 69 6d 7d 0a | 20 20 20 20 23 21 20 2f |rbatim}.| #! /|
|00001570| 75 73 72 2f 6c 6f 63 61 | 6c 2f 70 75 62 2f 62 69 |usr/loca|l/pub/bi|
|00001580| 6e 2f 65 6c 6b 0a 20 20 | 20 20 3b 3b 20 64 69 66 |n/elk. | ;; dif|
|00001590| 66 64 69 72 2e 65 73 68 | 20 2d 20 63 6f 6d 70 61 |fdir.esh| - compa|
|000015a0| 72 65 20 66 69 6c 65 73 | 20 74 6f 20 74 68 6f 73 |re files| to thos|
|000015b0| 65 20 69 6e 20 61 6e 6f | 74 68 65 72 20 64 69 72 |e in ano|ther dir|
|000015c0| 65 63 74 6f 72 79 0a 20 | 20 20 20 0a 20 20 20 20 |ectory. | . |
|000015d0| 28 6c 6f 61 64 20 22 73 | 68 65 6c 6c 2e 65 22 29 |(load "s|hell.e")|
|000015e0| 20 20 20 20 20 20 20 20 | 20 20 20 20 3b 20 6c 6f | | ; lo|
|000015f0| 61 64 20 64 65 63 6c 61 | 72 65 2d 73 68 65 6c 6c |ad decla|re-shell|
|00001600| 20 66 65 61 74 75 72 65 | 0a 20 20 20 20 28 64 65 | feature|. (de|
|00001610| 63 6c 61 72 65 2d 73 68 | 65 6c 6c 20 64 69 66 66 |clare-sh|ell diff|
|00001620| 29 0a 20 20 20 20 0a 20 | 20 20 20 28 64 65 66 69 |). . | (defi|
|00001630| 6e 65 20 24 63 6c 61 72 | 67 73 20 28 63 64 72 20 |ne $clar|gs (cdr |
|00001640| 28 63 6f 6d 6d 61 6e 64 | 2d 6c 69 6e 65 2d 61 72 |(command|-line-ar|
|00001650| 67 73 29 29 29 20 3b 20 | 73 6b 69 70 20 61 72 67 |gs))) ; |skip arg|
|00001660| 30 20 0a 20 20 20 20 28 | 73 65 74 21 20 24 63 6c |0 . (|set! $cl|
|00001670| 61 72 67 73 20 28 72 65 | 76 65 72 73 65 20 24 63 |args (re|verse $c|
|00001680| 6c 61 72 67 73 29 29 20 | 20 20 20 20 20 20 20 20 |largs)) | |
|00001690| 20 20 3b 20 72 65 76 65 | 72 73 65 0a 20 20 20 20 | ; reve|rse. |
|000016a0| 28 64 65 66 69 6e 65 20 | 24 64 69 72 20 28 63 61 |(define |$dir (ca|
|000016b0| 72 20 24 63 6c 61 72 67 | 73 29 29 20 20 20 20 20 |r $clarg|s)) |
|000016c0| 20 20 20 20 3b 20 67 65 | 74 20 6c 61 73 74 20 61 | ; ge|t last a|
|000016d0| 72 67 20 3d 20 64 69 72 | 65 63 74 6f 72 79 0a 20 |rg = dir|ectory. |
|000016e0| 20 20 20 28 73 65 74 21 | 20 24 63 6c 61 72 67 73 | (set!| $clargs|
|000016f0| 20 28 63 64 72 20 24 63 | 6c 61 72 67 73 29 29 20 | (cdr $c|largs)) |
|00001700| 20 20 20 20 20 20 20 3b | 20 73 6b 69 70 20 64 69 | ;| skip di|
|00001710| 72 65 63 74 6f 72 79 0a | 20 20 20 20 0a 20 20 20 |rectory.| . |
|00001720| 20 28 64 6f 6c 69 73 74 | 20 28 24 66 69 6c 65 20 | (dolist| ($file |
|00001730| 24 63 6c 61 72 67 73 29 | 20 20 20 20 20 20 20 20 |$clargs)| |
|00001740| 20 20 20 20 20 3b 20 6c | 6f 6f 70 20 6f 76 65 72 | ; l|oop over|
|00001750| 20 66 69 6c 65 73 0a 20 | 20 20 20 20 20 20 20 28 | files. | (|
|00001760| 70 72 69 6e 74 20 24 66 | 69 6c 65 29 20 20 20 20 |print $f|ile) |
|00001770| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 3b | | ;|
|00001780| 20 70 72 69 6e 74 20 66 | 69 6c 65 6e 61 6d 65 0a | print f|ilename.|
|00001790| 20 20 20 20 20 20 20 20 | 28 64 69 66 66 20 24 66 | |(diff $f|
|000017a0| 69 6c 65 20 28 73 74 72 | 69 6e 67 2d 61 70 70 65 |ile (str|ing-appe|
|000017b0| 6e 64 20 24 64 69 72 20 | 22 2f 22 20 24 66 69 6c |nd $dir |"/" $fil|
|000017c0| 65 29 29 20 3b 20 64 6f | 20 64 69 66 66 0a 20 20 |e)) ; do| diff. |
|000017d0| 20 20 29 0a 20 20 20 20 | 28 65 78 69 74 20 30 29 | ). |(exit 0)|
|000017e0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|000017f0| 20 20 20 20 20 20 20 20 | 20 20 20 20 3b 20 65 78 | | ; ex|
|00001800| 69 74 0a 5c 65 6e 64 7b | 76 65 72 62 61 74 69 6d |it.\end{|verbatim|
|00001810| 7d 0a 54 68 69 73 20 73 | 68 65 6c 6c 20 6d 69 67 |}.This s|hell mig|
|00001820| 68 74 20 62 65 20 63 61 | 6c 6c 65 64 20 61 73 0a |ht be ca|lled as.|
|00001830| 5c 62 65 67 69 6e 7b 76 | 65 72 62 61 74 69 6d 7d |\begin{v|erbatim}|
|00001840| 0a 20 20 20 20 64 69 66 | 66 64 69 72 2e 65 73 68 |. dif|fdir.esh|
|00001850| 20 2a 2e 63 20 2e 2e 2f | 6f 6c 64 76 65 72 73 69 | *.c ../|oldversi|
|00001860| 6f 6e 0a 5c 65 6e 64 7b | 76 65 72 62 61 74 69 6d |on.\end{|verbatim|
|00001870| 7d 0a 54 68 65 20 66 69 | 72 73 74 20 64 65 66 69 |}.The fi|rst defi|
|00001880| 6e 65 20 73 6b 69 70 73 | 20 74 68 65 20 66 69 72 |ne skips| the fir|
|00001890| 73 74 20 61 72 67 75 6d | 65 6e 74 2c 20 77 68 69 |st argum|ent, whi|
|000018a0| 63 68 20 69 73 20 74 68 | 65 20 70 72 6f 67 72 61 |ch is th|e progra|
|000018b0| 6d 20 6e 61 6d 65 2e 0a | 47 6c 6f 62 61 6c 20 76 |m name..|Global v|
|000018c0| 61 72 69 61 62 6c 65 73 | 20 68 61 76 65 20 62 65 |ariables| have be|
|000018d0| 65 6e 20 6e 61 6d 65 64 | 20 5c 24 76 61 72 2c 20 |en named| \$var, |
|000018e0| 72 65 73 65 6d 62 6c 69 | 6e 67 20 73 68 65 6c 6c |resembli|ng shell|
|000018f0| 20 76 61 72 69 61 62 6c | 65 73 2e 0a 54 68 69 73 | variabl|es..This|
|00001900| 20 69 73 20 6a 75 73 74 | 20 61 20 6e 61 6d 69 6e | is just| a namin|
|00001910| 67 20 63 6f 6e 76 65 6e | 74 69 6f 6e 3a 20 53 63 |g conven|tion: Sc|
|00001920| 68 65 6d 65 20 76 61 72 | 69 61 62 6c 65 73 20 63 |heme var|iables c|
|00001930| 61 6e 20 69 6e 63 6c 75 | 64 65 0a 63 68 61 72 61 |an inclu|de.chara|
|00001940| 63 74 65 72 73 20 73 75 | 63 68 20 61 73 20 7b 5c |cters su|ch as {\|
|00001950| 74 74 20 5c 24 2c 2a 2c | 2d 2c 5c 25 2c 21 20 7d |tt \$,*,|-,\%,! }|
|00001960| 2e 0a 0a 53 6f 6d 65 20 | 63 6f 72 72 65 73 70 6f |...Some |correspo|
|00001970| 6e 64 69 6e 67 20 42 6f | 75 72 6e 65 20 73 68 65 |nding Bo|urne she|
|00001980| 6c 6c 20 63 6f 64 65 20 | 69 73 3a 0a 5c 62 65 67 |ll code |is:.\beg|
|00001990| 69 6e 7b 76 65 72 62 61 | 74 69 6d 7d 0a 20 20 20 |in{verba|tim}. |
|000019a0| 20 23 21 20 2f 62 69 6e | 2f 73 68 0a 20 20 20 20 | #! /bin|/sh. |
|000019b0| 0a 20 20 20 20 66 6f 72 | 20 66 69 6c 65 20 69 6e |. for| file in|
|000019c0| 20 24 63 6c 61 72 67 73 | 20 64 6f 20 3b 0a 20 20 | $clargs| do ;. |
|000019d0| 20 20 20 20 20 20 65 63 | 68 6f 20 24 66 69 6c 65 | ec|ho $file|
|000019e0| 20 3b 0a 20 20 20 20 20 | 20 20 20 64 69 66 66 20 | ;. | diff |
|000019f0| 24 66 69 6c 65 20 24 64 | 69 72 20 3b 0a 20 20 20 |$file $d|ir ;. |
|00001a00| 20 64 6f 6e 65 0a 5c 65 | 6e 64 7b 76 65 72 62 61 | done.\e|nd{verba|
|00001a10| 74 69 6d 7d 0a 62 75 74 | 20 74 68 69 73 20 65 78 |tim}.but| this ex|
|00001a20| 61 6d 70 6c 65 20 69 73 | 20 6d 69 73 73 69 6e 67 |ample is| missing|
|00001a30| 20 74 68 65 20 61 72 67 | 75 6d 65 6e 74 20 70 61 | the arg|ument pa|
|00001a40| 72 73 69 6e 67 20 6e 65 | 63 65 73 73 61 72 79 20 |rsing ne|cessary |
|00001a50| 74 6f 20 0a 65 78 74 72 | 61 63 74 20 74 68 65 20 |to .extr|act the |
|00001a60| 6c 61 73 74 20 63 6f 6d | 6d 61 6e 64 20 6c 69 6e |last com|mand lin|
|00001a70| 65 20 61 72 67 75 6d 65 | 6e 74 20 61 6e 64 20 70 |e argume|nt and p|
|00001a80| 75 74 20 69 74 20 69 6e | 20 74 68 65 20 76 61 72 |ut it in| the var|
|00001a90| 69 61 62 6c 65 20 5c 24 | 64 69 72 2e 0a 0a 5c 73 |iable \$|dir...\s|
|00001aa0| 75 62 73 65 63 74 69 6f | 6e 7b 45 78 61 6d 70 6c |ubsectio|n{Exampl|
|00001ab0| 65 20 2d 20 72 65 6e 61 | 6d 65 73 74 61 72 7d 0a |e - rena|mestar}.|
|00001ac0| 0a 54 68 69 73 20 73 68 | 65 6c 6c 20 72 65 6e 61 |.This sh|ell rena|
|00001ad0| 6d 65 73 20 61 20 6e 75 | 6d 62 65 72 20 6f 66 20 |mes a nu|mber of |
|00001ae0| 66 69 6c 65 73 2c 20 72 | 65 70 6c 61 63 69 6e 67 |files, r|eplacing|
|00001af0| 20 61 20 73 75 62 73 74 | 72 69 6e 67 2e 0a 46 6f | a subst|ring..Fo|
|00001b00| 72 20 65 78 61 6d 70 6c | 65 2c 20 0a 5c 62 65 67 |r exampl|e, .\beg|
|00001b10| 69 6e 7b 76 65 72 62 61 | 74 69 6d 7d 0a 20 20 20 |in{verba|tim}. |
|00001b20| 20 72 65 6e 61 6d 65 73 | 74 61 72 2e 65 73 68 20 | renames|tar.esh |
|00001b30| 22 2a 2e 63 73 68 22 20 | 2e 63 73 68 20 5f 63 73 |"*.csh" |.csh _cs|
|00001b40| 68 0a 5c 65 6e 64 7b 76 | 65 72 62 61 74 69 6d 7d |h.\end{v|erbatim}|
|00001b50| 0a 77 69 6c 6c 20 72 65 | 6e 61 6d 65 20 61 6c 6c |.will re|name all|
|00001b60| 20 2a 2e 63 73 68 20 66 | 69 6c 65 73 20 74 6f 20 | *.csh f|iles to |
|00001b70| 2a 5c 5f 63 73 68 2e 0a | 4e 6f 74 65 20 74 68 61 |*\_csh..|Note tha|
|00001b80| 74 20 69 74 20 69 73 20 | 6e 65 63 65 73 73 61 72 |t it is |necessar|
|00001b90| 79 20 74 6f 20 71 75 6f | 74 65 20 74 68 65 20 66 |y to quo|te the f|
|00001ba0| 69 6c 65 20 70 61 74 74 | 65 72 6e 20 60 60 2a 2e |ile patt|ern ``*.|
|00001bb0| 63 73 68 27 27 0a 73 69 | 6e 63 65 20 69 74 20 69 |csh''.si|nce it i|
|00001bc0| 73 20 65 78 70 61 6e 64 | 65 64 20 62 79 20 74 68 |s expand|ed by th|
|00001bd0| 65 20 45 6c 6b 20 73 68 | 65 6c 6c 2c 20 6e 6f 74 |e Elk sh|ell, not|
|00001be0| 20 74 68 65 20 63 61 6c | 6c 69 6e 67 20 73 68 65 | the cal|ling she|
|00001bf0| 6c 6c 0a 28 74 68 69 73 | 20 6d 61 6b 65 73 20 74 |ll.(this| makes t|
|00001c00| 68 65 20 45 6c 6b 20 73 | 68 65 6c 6c 27 73 20 61 |he Elk s|hell's a|
|00001c10| 72 67 75 6d 65 6e 74 20 | 70 61 72 73 69 6e 67 20 |rgument |parsing |
|00001c20| 65 61 73 69 65 72 2d 2d | 0a 74 68 65 20 6f 6c 64 |easier--|.the old|
|00001c30| 20 61 6e 64 20 6e 65 77 | 20 6e 61 6d 65 20 73 75 | and new| name su|
|00001c40| 62 73 74 72 69 6e 67 73 | 20 61 72 65 20 61 6c 77 |bstrings| are alw|
|00001c50| 61 79 73 20 69 6e 20 74 | 68 65 20 5c 24 32 20 61 |ays in t|he \$2 a|
|00001c60| 6e 64 20 5c 24 33 20 61 | 72 67 75 6d 65 6e 74 73 |nd \$3 a|rguments|
|00001c70| 29 2e 0a 52 65 6e 61 6d | 65 73 74 61 72 3a 0a 0a |)..Renam|estar:..|
|00001c80| 5c 62 65 67 69 6e 7b 76 | 65 72 62 61 74 69 6d 7d |\begin{v|erbatim}|
|00001c90| 0a 20 20 20 20 23 21 20 | 2f 75 73 72 2f 6c 6f 63 |. #! |/usr/loc|
|00001ca0| 61 6c 2f 70 75 62 2f 62 | 69 6e 2f 65 6c 6b 0a 20 |al/pub/b|in/elk. |
|00001cb0| 20 20 20 28 6c 6f 61 64 | 20 22 63 6c 61 72 67 73 | (load| "clargs|
|00001cc0| 2e 65 22 29 20 20 20 20 | 20 20 20 20 20 20 20 20 |.e") | |
|00001cd0| 20 20 20 20 20 20 20 3b | 20 62 69 6e 64 20 61 72 | ;| bind ar|
|00001ce0| 67 75 6d 65 6e 74 73 20 | 74 6f 20 24 31 2c 24 32 |guments |to $1,$2|
|00001cf0| 2c 65 74 63 0a 20 20 20 | 20 0a 20 20 20 20 28 77 |,etc. | . (w|
|00001d00| 68 65 6e 20 28 6e 6f 74 | 20 24 33 29 0a 20 20 20 |hen (not| $3). |
|00001d10| 20 20 20 20 20 20 20 28 | 70 72 69 6e 74 20 22 72 | (|print "r|
|00001d20| 65 6e 61 6d 65 73 74 61 | 72 2e 65 73 68 20 3c 2a |enamesta|r.esh <*|
|00001d30| 66 69 6c 65 2a 3e 20 3c | 73 75 62 73 74 72 69 6e |file*> <|substrin|
|00001d40| 67 3e 20 3c 72 65 70 6c | 61 63 65 3e 22 29 0a 20 |g> <repl|ace>"). |
|00001d50| 20 20 20 20 20 20 20 20 | 20 28 70 72 69 6e 74 20 | | (print |
|00001d60| 22 72 65 6e 61 6d 65 73 | 20 2a 66 69 6c 65 2a 20 |"renames| *file* |
|00001d70| 72 65 70 6c 61 63 69 6e | 67 20 73 75 62 73 74 72 |replacin|g substr|
|00001d80| 69 6e 67 20 77 69 74 68 | 20 72 65 70 6c 61 63 65 |ing with| replace|
|00001d90| 2e 22 29 0a 20 20 20 20 | 20 20 20 20 20 20 28 65 |."). | (e|
|00001da0| 78 69 74 20 31 29 0a 20 | 20 20 20 29 0a 20 20 20 |xit 1). | ). |
|00001db0| 20 0a 20 20 20 20 28 64 | 65 66 69 6e 65 20 66 69 | . (d|efine fi|
|00001dc0| 6c 65 73 20 28 6f 73 2d | 67 6c 6f 62 20 24 31 29 |les (os-|glob $1)|
|00001dd0| 29 20 20 20 20 20 20 20 | 20 20 3b 20 6c 69 73 74 |) | ; list|
|00001de0| 20 6f 66 20 6d 61 74 63 | 68 69 6e 67 20 66 69 6c | of matc|hing fil|
|00001df0| 65 73 0a 20 20 20 20 28 | 64 65 66 69 6e 65 20 73 |es. (|define s|
|00001e00| 75 62 6c 65 6e 20 28 73 | 74 72 69 6e 67 2d 6c 65 |ublen (s|tring-le|
|00001e10| 6e 67 74 68 20 24 32 29 | 29 20 20 3b 20 6c 65 6e |ngth $2)|) ; len|
|00001e20| 67 74 68 20 6f 66 20 73 | 75 62 73 74 72 69 6e 67 |gth of s|ubstring|
|00001e30| 20 0a 20 20 20 20 0a 20 | 20 20 20 28 64 6f 6c 69 | . . | (doli|
|00001e40| 73 74 20 28 66 69 6c 65 | 20 66 69 6c 65 73 29 20 |st (file| files) |
|00001e50| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 3b | | ;|
|00001e60| 20 6c 6f 6f 70 20 6f 76 | 65 72 20 66 69 6c 65 73 | loop ov|er files|
|00001e70| 0a 20 20 20 20 20 20 28 | 6c 65 74 20 20 28 28 73 |. (|let ((s|
|00001e80| 20 28 73 75 62 73 74 72 | 69 6e 67 3f 20 24 32 20 | (substr|ing? $2 |
|00001e90| 66 69 6c 65 29 29 29 20 | 20 3b 20 69 73 20 73 75 |file))) | ; is su|
|00001ea0| 62 73 74 72 69 6e 67 20 | 69 6e 20 74 68 69 73 20 |bstring |in this |
|00001eb0| 66 69 6c 65 6e 61 6d 65 | 3f 0a 20 20 20 20 20 20 |filename|?. |
|00001ec0| 20 20 28 77 68 65 6e 20 | 73 20 20 20 20 20 20 20 | (when |s |
|00001ed0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00001ee0| 20 20 3b 20 69 66 20 73 | 6f 2c 20 62 65 67 69 6e | ; if s|o, begin|
|00001ef0| 0a 20 20 20 20 20 20 20 | 20 20 20 28 6c 65 74 20 |. | (let |
|00001f00| 28 28 6e 65 77 6e 61 6d | 65 20 20 20 20 20 20 20 |((newnam|e |
|00001f10| 20 20 20 20 20 20 20 20 | 20 3b 20 6e 65 77 6e 61 | | ; newna|
|00001f20| 6d 65 20 69 73 0a 20 20 | 20 20 20 20 20 20 20 20 |me is. | |
|00001f30| 20 20 20 20 20 20 20 28 | 73 74 72 69 6e 67 2d 61 | (|string-a|
|00001f40| 70 70 65 6e 64 20 20 20 | 20 20 20 20 20 20 3b 20 |ppend | ; |
|00001f50| 63 6f 6e 63 61 74 65 6e | 61 74 69 6f 6e 20 6f 66 |concaten|ation of|
|00001f60| 0a 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |. | |
|00001f70| 20 20 20 28 73 75 62 73 | 74 72 69 6e 67 20 66 69 | (subs|tring fi|
|00001f80| 6c 65 20 30 20 73 29 20 | 20 3b 20 70 6f 72 74 69 |le 0 s) | ; porti|
|00001f90| 6f 6e 20 62 65 66 6f 72 | 65 20 73 75 62 73 74 72 |on befor|e substr|
|00001fa0| 69 6e 67 0a 20 20 20 20 | 20 20 20 20 20 20 20 20 |ing. | |
|00001fb0| 20 20 20 20 20 20 24 33 | 20 20 20 20 20 20 20 20 | $3| |
|00001fc0| 20 20 20 20 20 20 20 20 | 20 20 20 20 3b 20 72 65 | | ; re|
|00001fd0| 70 6c 61 63 65 6d 65 6e | 74 2c 20 0a 20 20 20 20 |placemen|t, . |
|00001fe0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00001ff0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00002000| 20 20 20 20 3b 20 61 6e | 64 20 70 6f 72 74 69 6f | ; an|d portio|
|00002010| 6e 20 61 66 74 65 72 20 | 73 75 62 73 74 72 69 6e |n after |substrin|
|00002020| 67 3a 0a 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |g:. | |
|00002030| 20 20 20 20 20 28 73 75 | 62 73 74 72 69 6e 67 20 | (su|bstring |
|00002040| 66 69 6c 65 20 28 2b 20 | 73 20 73 75 62 6c 65 6e |file (+ |s sublen|
|00002050| 29 20 28 73 74 72 69 6e | 67 2d 6c 65 6e 67 74 68 |) (strin|g-length|
|00002060| 20 66 69 6c 65 29 29 0a | 20 20 20 20 20 20 20 20 | file)).| |
|00002070| 20 20 20 20 20 20 20 20 | 20 29 29 0a 20 20 20 20 | | )). |
|00002080| 20 20 20 20 20 20 20 20 | 20 20 20 20 29 3b 6c 65 | | );le|
|00002090| 74 62 69 6e 64 69 6e 67 | 0a 20 20 20 20 20 20 20 |tbinding|. |
|000020a0| 20 20 20 20 20 28 66 6f | 72 6d 61 74 20 23 74 20 | (fo|rmat #t |
|000020b0| 22 7e 61 20 2d 3e 20 7e | 61 7e 25 22 20 66 69 6c |"~a -> ~|a~%" fil|
|000020c0| 65 20 6e 65 77 6e 61 6d | 65 29 20 3b 20 70 72 69 |e newnam|e) ; pri|
|000020d0| 6e 74 20 61 63 74 69 6f | 6e 0a 20 20 20 20 20 20 |nt actio|n. |
|000020e0| 20 20 20 20 20 20 28 6f | 73 2d 72 65 6e 61 6d 65 | (o|s-rename|
|000020f0| 2d 66 69 6c 65 20 66 69 | 6c 65 20 6e 65 77 6e 61 |-file fi|le newna|
|00002100| 6d 65 29 20 3b 20 72 65 | 6e 61 6d 65 20 69 74 0a |me) ; re|name it.|
|00002110| 20 20 20 20 20 20 20 20 | 20 20 29 3b 6c 65 74 0a | | );let.|
|00002120| 20 20 20 20 20 20 20 20 | 29 3b 77 68 65 6e 20 73 | |);when s|
|00002130| 0a 20 20 20 20 20 20 29 | 3b 6c 65 74 0a 20 20 20 |. )|;let. |
|00002140| 20 29 3b 64 6f 6c 69 73 | 74 0a 20 20 20 20 0a 20 | );dolis|t. . |
|00002150| 20 20 20 28 65 78 69 74 | 20 30 29 0a 5c 65 6e 64 | (exit| 0).\end|
|00002160| 7b 76 65 72 62 61 74 69 | 6d 7d 0a 0a 54 68 65 20 |{verbati|m}..The |
|00002170| 6c 69 62 72 61 72 79 20 | 66 69 6c 65 20 63 6c 61 |library |file cla|
|00002180| 72 67 73 2e 65 20 62 69 | 6e 64 73 20 74 68 65 20 |rgs.e bi|nds the |
|00002190| 63 6f 6d 6d 61 6e 64 20 | 6c 69 6e 65 20 61 72 67 |command |line arg|
|000021a0| 75 6d 65 6e 74 20 73 74 | 72 69 6e 67 73 20 0a 74 |ument st|rings .t|
|000021b0| 6f 20 74 68 65 20 73 63 | 68 65 6d 65 20 76 61 72 |o the sc|heme var|
|000021c0| 69 61 62 6c 65 73 20 5c | 24 31 2c 5c 24 32 2c 2e |iables \|$1,\$2,.|
|000021d0| 2e 2e 3b 0a 5c 24 6e 20 | 69 73 20 62 6f 75 6e 64 |..;.\$n |is bound|
|000021e0| 20 74 6f 20 27 28 29 20 | 69 66 20 74 68 65 72 65 | to '() |if there|
|000021f0| 20 69 73 20 6e 6f 20 63 | 6f 72 72 65 73 70 6f 6e | is no c|orrespon|
|00002200| 64 69 6e 67 20 61 72 67 | 75 6d 65 6e 74 2e 0a 54 |ding arg|ument..T|
|00002210| 68 65 20 73 74 61 74 65 | 6d 65 6e 74 20 22 28 77 |he state|ment "(w|
|00002220| 68 65 6e 20 5c 24 33 20 | 2e 2e 2e 22 20 74 65 73 |hen \$3 |..." tes|
|00002230| 74 73 20 74 68 61 74 20 | 61 74 20 6c 65 61 73 74 |ts that |at least|
|00002240| 20 74 68 72 65 65 20 61 | 72 67 75 6d 65 6e 74 73 | three a|rguments|
|00002250| 0a 61 72 65 20 73 75 70 | 70 6c 69 65 64 20 61 6e |.are sup|plied an|
|00002260| 64 20 70 72 69 6e 74 73 | 20 61 6e 20 75 73 61 67 |d prints| an usag|
|00002270| 65 20 6d 65 73 73 61 67 | 65 20 69 66 20 6e 65 63 |e messag|e if nec|
|00002280| 65 73 73 61 72 79 2e 0a | 0a 5c 73 75 62 73 65 63 |essary..|.\subsec|
|00002290| 74 69 6f 6e 7b 45 78 61 | 6d 70 6c 65 20 2d 20 74 |tion{Exa|mple - t|
|000022a0| 72 61 76 65 72 73 65 7d | 0a 0a 54 68 65 20 6c 69 |raverse}|..The li|
|000022b0| 62 72 61 72 79 20 66 69 | 6c 65 20 74 72 61 76 65 |brary fi|le trave|
|000022c0| 72 73 65 64 69 72 2e 65 | 20 63 6f 6e 74 61 69 6e |rsedir.e| contain|
|000022d0| 73 20 61 20 66 75 6e 63 | 74 69 6f 6e 20 5c 76 65 |s a func|tion \ve|
|000022e0| 72 62 7c 74 72 61 76 65 | 72 73 65 2d 70 7c 0a 77 |rb|trave|rse-p|.w|
|000022f0| 68 69 63 68 20 77 61 6c | 6b 73 20 64 6f 77 6e 20 |hich wal|ks down |
|00002300| 61 20 64 69 72 65 63 74 | 6f 72 79 20 74 72 65 65 |a direct|ory tree|
|00002310| 2c 20 63 61 6c 6c 69 6e | 67 20 61 20 73 75 70 70 |, callin|g a supp|
|00002320| 6c 69 65 64 20 66 75 6e | 63 74 69 6f 6e 0a 77 69 |lied fun|ction.wi|
|00002330| 74 68 20 74 68 65 20 6e | 61 6d 65 20 6f 66 20 65 |th the n|ame of e|
|00002340| 61 63 68 20 66 69 6c 65 | 20 69 6e 20 74 68 65 20 |ach file| in the |
|00002350| 74 72 65 65 2e 0a 5c 62 | 65 67 69 6e 7b 76 65 72 |tree..\b|egin{ver|
|00002360| 62 61 74 69 6d 7d 0a 20 | 20 20 20 28 64 65 66 69 |batim}. | (defi|
|00002370| 6e 65 20 28 74 72 61 76 | 65 72 73 65 2d 70 20 70 |ne (trav|erse-p p|
|00002380| 61 74 68 20 64 6f 66 69 | 6c 65 29 0a 20 20 20 20 |ath dofi|le). |
|00002390| 0a 20 20 20 20 20 20 20 | 20 28 64 65 66 69 6e 65 |. | (define|
|000023a0| 20 28 74 72 61 76 65 72 | 73 65 2d 70 2d 64 69 72 | (traver|se-p-dir|
|000023b0| 20 70 61 74 68 20 64 6f | 66 69 6c 65 29 20 20 3b | path do|file) ;|
|000023c0| 20 68 65 6c 70 65 72 20 | 66 75 6e 63 74 69 6f 6e | helper |function|
|000023d0| 0a 20 20 20 20 20 20 20 | 20 20 20 28 6c 65 74 20 |. | (let |
|000023e0| 28 28 64 69 72 20 28 72 | 65 61 64 2d 64 69 72 65 |((dir (r|ead-dire|
|000023f0| 63 74 6f 72 79 20 70 61 | 74 68 29 29 29 20 20 3b |ctory pa|th))) ;|
|00002400| 20 72 65 61 64 20 64 69 | 72 65 63 74 6f 72 79 0a | read di|rectory.|
|00002410| 20 20 20 20 20 20 20 20 | 20 20 20 20 28 66 6f 72 | | (for|
|00002420| 6d 61 74 20 23 74 20 22 | 74 72 61 76 65 72 73 69 |mat #t "|traversi|
|00002430| 6e 67 20 7e 61 7e 25 22 | 20 70 61 74 68 29 0a 20 |ng ~a~%"| path). |
|00002440| 20 20 20 20 20 20 20 20 | 20 20 20 28 64 6f 6c 69 | | (doli|
|00002450| 73 74 20 28 65 6e 74 72 | 79 20 64 69 72 29 20 20 |st (entr|y dir) |
|00002460| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 3b 20 6c | | ; l|
|00002470| 6f 6f 70 20 6f 76 65 72 | 20 66 69 6c 65 73 0a 20 |oop over| files. |
|00002480| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 28 69 66 | | (if|
|00002490| 20 28 6e 6f 74 20 28 6d | 65 6d 62 65 72 20 65 6e | (not (m|ember en|
|000024a0| 74 72 79 20 27 28 22 2e | 22 20 22 2e 2e 22 29 29 |try '(".|" ".."))|
|000024b0| 29 20 3b 20 69 66 20 6e | 6f 74 20 2e 2c 2e 2e 0a |) ; if n|ot .,...|
|000024c0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|000024d0| 20 20 28 74 72 61 76 65 | 72 73 65 2d 70 20 20 20 | (trave|rse-p |
|000024e0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 3b 20 | | ; |
|000024f0| 72 65 63 75 72 73 65 0a | 20 20 20 20 20 20 20 20 |recurse.| |
|00002500| 20 20 20 20 20 20 20 20 | 20 20 20 28 73 74 72 69 | | (stri|
|00002510| 6e 67 2d 61 70 70 65 6e | 64 20 70 61 74 68 20 22 |ng-appen|d path "|
|00002520| 2f 22 20 65 6e 74 72 79 | 29 0a 20 20 20 20 20 20 |/" entry|). |
|00002530| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 64 6f 66 | | dof|
|00002540| 69 6c 65 29 29 0a 20 20 | 20 20 20 20 20 20 20 20 |ile)). | |
|00002550| 20 20 29 3b 64 6f 6c 69 | 73 74 0a 20 20 20 20 20 | );doli|st. |
|00002560| 20 20 20 20 20 29 3b 6c | 65 74 0a 20 20 20 20 20 | );l|et. |
|00002570| 20 20 20 29 3b 74 72 61 | 76 65 72 73 65 2d 70 2d | );tra|verse-p-|
|00002580| 64 69 72 0a 0a 20 20 20 | 20 20 20 3b 3b 20 62 65 |dir.. | ;; be|
|00002590| 67 69 6e 20 74 72 61 76 | 65 72 73 65 2d 70 20 66 |gin trav|erse-p f|
|000025a0| 75 6e 63 74 69 6f 6e 0a | 20 20 20 20 20 20 28 69 |unction.| (i|
|000025b0| 66 20 28 65 71 75 61 6c | 3f 20 27 72 65 67 75 6c |f (equal|? 'regul|
|000025c0| 61 72 20 28 66 69 6c 65 | 2d 73 74 61 74 75 73 20 |ar (file|-status |
|000025d0| 70 61 74 68 29 29 0a 20 | 20 20 20 0a 20 20 20 20 |path)). | . |
|000025e0| 20 20 20 20 20 20 28 64 | 6f 66 69 6c 65 20 70 61 | (d|ofile pa|
|000025f0| 74 68 29 0a 20 20 20 20 | 0a 20 20 20 20 20 20 20 |th). |. |
|00002600| 20 20 20 3b 20 65 6c 73 | 65 20 6e 6f 74 20 72 65 | ; els|e not re|
|00002610| 67 75 6c 61 72 20 66 69 | 6c 65 20 2d 20 61 20 6c |gular fi|le - a l|
|00002620| 69 6e 6b 20 6f 72 20 64 | 69 72 65 63 74 6f 72 79 |ink or d|irectory|
|00002630| 0a 20 20 20 20 20 20 20 | 20 20 20 28 69 66 20 28 |. | (if (|
|00002640| 66 69 6c 65 2d 65 78 69 | 73 74 73 3f 20 70 61 74 |file-exi|sts? pat|
|00002650| 68 29 20 20 20 20 20 20 | 20 3b 64 6f 20 6e 6f 74 |h) | ;do not|
|00002660| 20 74 72 79 20 74 6f 20 | 72 65 61 64 20 6e 6f 6e | try to |read non|
|00002670| 65 78 69 73 74 65 6e 74 | 20 6c 69 6e 6b 73 0a 20 |existent| links. |
|00002680| 20 20 20 20 20 20 20 20 | 20 28 74 72 61 76 65 72 | | (traver|
|00002690| 73 65 2d 70 2d 64 69 72 | 20 70 61 74 68 20 64 6f |se-p-dir| path do|
|000026a0| 66 69 6c 65 29 29 20 3b | 64 65 73 63 65 6e 64 20 |file)) ;|descend |
|000026b0| 69 6e 74 6f 20 64 69 72 | 65 63 74 6f 72 79 0a 20 |into dir|ectory. |
|000026c0| 20 20 20 20 20 29 0a 20 | 20 20 20 29 3b 74 72 61 | ). | );tra|
|000026d0| 76 65 72 73 65 2d 70 0a | 5c 65 6e 64 7b 76 65 72 |verse-p.|\end{ver|
|000026e0| 62 61 74 69 6d 7d 0a 54 | 68 69 73 20 73 69 6d 70 |batim}.T|his simp|
|000026f0| 6c 65 20 66 75 6e 63 74 | 69 6f 6e 20 70 65 72 6d |le funct|ion perm|
|00002700| 69 74 73 20 74 68 65 20 | 63 6f 6e 73 74 72 75 63 |its the |construc|
|00002710| 74 69 6f 6e 20 6f 66 20 | 73 68 65 6c 6c 73 20 0a |tion of |shells .|
|00002720| 77 69 74 68 20 74 61 73 | 6b 73 20 73 69 6d 69 6c |with tas|ks simil|
|00002730| 61 72 20 74 6f 20 66 69 | 6e 64 28 31 29 2c 20 61 |ar to fi|nd(1), a|
|00002740| 73 20 77 65 6c 6c 20 61 | 73 20 64 69 72 65 63 74 |s well a|s direct|
|00002750| 6f 72 79 20 6d 61 6e 61 | 67 65 6d 65 6e 74 0a 74 |ory mana|gement.t|
|00002760| 61 73 6b 73 20 77 68 69 | 63 68 20 61 72 65 20 6e |asks whi|ch are n|
|00002770| 6f 74 20 65 61 73 79 20 | 74 6f 20 61 63 63 6f 6d |ot easy |to accom|
|00002780| 70 6c 69 73 68 20 69 6e | 20 66 69 6e 64 2e 0a 0a |plish in| find...|
|00002790| 46 6f 72 20 65 78 61 6d | 70 6c 65 2c 20 74 68 69 |For exam|ple, thi|
|000027a0| 73 20 73 68 65 6c 6c 20 | 64 65 6c 65 74 65 73 20 |s shell |deletes |
|000027b0| 63 6f 72 65 20 66 69 6c | 65 73 20 66 72 6f 6d 20 |core fil|es from |
|000027c0| 74 68 65 20 68 6f 6d 65 | 20 64 69 72 65 63 74 6f |the home| directo|
|000027d0| 72 79 20 74 72 65 65 3a | 0a 5c 62 65 67 69 6e 7b |ry tree:|.\begin{|
|000027e0| 76 65 72 62 61 74 69 6d | 7d 0a 20 20 20 20 23 21 |verbatim|}. #!|
|000027f0| 20 2f 75 73 72 2f 6c 6f | 63 61 6c 2f 62 69 6e 2f | /usr/lo|cal/bin/|
|00002800| 65 6c 6b 0a 20 20 20 20 | 28 6c 6f 61 64 20 22 74 |elk. |(load "t|
|00002810| 72 61 76 65 72 73 65 2e | 65 22 29 0a 0a 20 20 20 |raverse.|e").. |
|00002820| 20 28 64 65 66 69 6e 65 | 20 28 64 65 6c 65 74 65 | (define| (delete|
|00002830| 2d 69 66 2d 63 6f 72 65 | 20 66 6e 61 6d 65 29 0a |-if-core| fname).|
|00002840| 20 20 20 20 20 20 28 69 | 66 20 28 65 71 75 61 6c | (i|f (equal|
|00002850| 3f 20 66 6e 61 6d 65 20 | 22 63 6f 72 65 22 29 20 |? fname |"core") |
|00002860| 28 6f 73 2d 64 65 6c 65 | 74 65 2d 66 69 6c 65 20 |(os-dele|te-file |
|00002870| 66 6e 61 6d 65 29 29 29 | 0a 0a 20 20 20 20 28 64 |fname)))|.. (d|
|00002880| 65 66 69 6e 65 20 24 48 | 4f 4d 45 20 28 6f 73 2d |efine $H|OME (os-|
|00002890| 67 65 74 65 6e 76 20 22 | 48 4f 4d 45 22 29 29 0a |getenv "|HOME")).|
|000028a0| 0a 20 20 20 20 28 74 72 | 61 76 65 72 73 65 2d 70 |. (tr|averse-p|
|000028b0| 20 24 48 4f 4d 45 20 64 | 65 6c 65 74 65 2d 69 66 | $HOME d|elete-if|
|000028c0| 2d 63 6f 72 65 29 0a 20 | 20 20 20 28 65 78 69 74 |-core). | (exit|
|000028d0| 20 30 29 0a 5c 65 6e 64 | 7b 76 65 72 62 61 74 69 | 0).\end|{verbati|
|000028e0| 6d 7d 0a 0a 5c 73 75 62 | 73 65 63 74 69 6f 6e 7b |m}..\sub|section{|
|000028f0| 45 78 61 6d 70 6c 65 20 | 2d 20 66 69 6c 65 73 77 |Example |- filesw|
|00002900| 68 65 6e 7d 0a 0a 54 68 | 69 73 20 73 75 62 72 6f |hen}..Th|is subro|
|00002910| 75 74 69 6e 65 20 75 73 | 65 73 20 74 72 61 65 72 |utine us|es traer|
|00002920| 73 65 20 74 6f 20 66 69 | 6e 64 73 20 61 6c 6c 20 |se to fi|nds all |
|00002930| 66 69 6c 65 73 20 63 72 | 65 61 74 65 64 20 0a 62 |files cr|eated .b|
|00002940| 65 74 77 65 65 6e 20 74 | 77 6f 20 73 70 65 63 69 |etween t|wo speci|
|00002950| 66 69 65 64 20 64 61 74 | 65 73 2e 0a 49 74 20 70 |fied dat|es..It p|
|00002960| 72 69 6e 74 73 20 61 20 | 6c 69 73 74 20 6f 66 20 |rints a |list of |
|00002970| 73 75 63 68 20 66 69 6c | 65 73 20 73 6f 72 74 65 |such fil|es sorte|
|00002980| 64 20 62 79 20 64 61 74 | 65 3a 0a 5c 62 65 67 69 |d by dat|e:.\begi|
|00002990| 6e 7b 76 65 72 62 61 74 | 69 6d 7d 0a 20 20 20 20 |n{verbat|im}. |
|000029a0| 28 6c 6f 61 64 20 22 74 | 72 61 76 65 72 73 65 2e |(load "t|raverse.|
|000029b0| 65 22 29 0a 20 20 20 20 | 3b 3b 20 70 72 69 6e 74 |e"). |;; print|
|000029c0| 20 74 69 6d 65 2d 73 6f | 72 74 65 64 20 6e 61 6d | time-so|rted nam|
|000029d0| 65 73 20 6f 66 20 66 69 | 6c 65 73 20 63 72 65 61 |es of fi|les crea|
|000029e0| 74 65 64 20 62 65 74 77 | 65 65 6e 20 74 77 6f 20 |ted betw|een two |
|000029f0| 64 61 74 65 73 0a 20 20 | 20 20 28 64 65 66 69 6e |dates. | (defin|
|00002a00| 65 20 28 66 69 6c 65 73 | 77 68 65 6e 20 61 66 74 |e (files|when aft|
|00002a10| 65 72 20 62 65 66 6f 72 | 65 29 0a 20 20 20 20 20 |er befor|e). |
|00002a20| 20 28 69 66 20 28 6e 6f | 74 20 28 62 6f 75 6e 64 | (if (no|t (bound|
|00002a30| 3f 20 27 73 6f 72 74 29 | 29 0a 20 20 20 20 20 20 |? 'sort)|). |
|00002a40| 20 20 20 20 28 6c 6f 61 | 64 20 22 73 6f 72 74 2e | (loa|d "sort.|
|00002a50| 73 63 6d 22 20 28 67 6c | 6f 62 61 6c 2d 65 6e 76 |scm" (gl|obal-env|
|00002a60| 69 72 6f 6e 6d 65 6e 74 | 29 29 29 0a 20 20 20 20 |ironment|))). |
|00002a70| 20 20 28 6c 65 74 20 28 | 28 6d 61 74 63 68 65 73 | (let (|(matches|
|00002a80| 20 27 28 29 29 0a 20 20 | 20 20 20 20 20 20 28 74 | '()). | (t|
|00002a90| 6d 69 6e 20 28 6f 73 2d | 70 61 72 73 65 74 69 6d |min (os-|parsetim|
|00002aa0| 65 20 61 66 74 65 72 29 | 29 0a 20 20 20 20 20 20 |e after)|). |
|00002ab0| 20 20 28 74 6d 61 78 20 | 28 6f 73 2d 70 61 72 73 | (tmax |(os-pars|
|00002ac0| 65 74 69 6d 65 20 62 65 | 66 6f 72 65 29 29 29 0a |etime be|fore))).|
|00002ad0| 20 20 20 20 20 20 20 20 | 28 69 66 20 28 6f 72 20 | |(if (or |
|00002ae0| 28 3d 20 30 20 74 6d 69 | 6e 29 20 28 3d 20 30 20 |(= 0 tmi|n) (= 0 |
|00002af0| 74 6d 61 78 29 29 0a 20 | 20 20 20 20 20 20 20 28 |tmax)). | (|
|00002b00| 65 72 72 6f 72 20 27 66 | 69 6c 65 73 77 68 65 6e |error 'f|ileswhen|
|00002b10| 20 22 62 61 64 20 74 69 | 6d 65 22 29 29 0a 20 20 | "bad ti|me")). |
|00002b20| 20 20 20 20 20 20 28 74 | 72 61 76 65 72 73 65 20 | (t|raverse |
|00002b30| 22 2e 22 0a 20 20 20 20 | 20 20 20 20 20 20 28 6c |".". | (l|
|00002b40| 61 6d 62 64 61 20 28 69 | 29 0a 20 20 20 20 20 20 |ambda (i|). |
|00002b50| 20 20 20 20 20 20 28 6c | 65 74 20 28 28 74 20 28 | (l|et ((t (|
|00002b60| 6f 73 2d 66 69 6c 65 6d | 6f 64 74 69 6d 65 20 69 |os-filem|odtime i|
|00002b70| 29 29 29 0a 20 20 20 20 | 20 20 20 20 20 20 20 20 |))). | |
|00002b80| 20 20 28 77 68 65 6e 20 | 28 61 6e 64 20 28 3e 3d | (when |(and (>=|
|00002b90| 20 74 20 74 6d 69 6e 29 | 20 28 3c 3d 20 74 20 74 | t tmin)| (<= t t|
|00002ba0| 6d 61 78 29 29 0a 20 20 | 20 20 20 20 20 20 20 20 |max)). | |
|00002bb0| 20 20 20 20 20 20 20 20 | 20 20 28 73 65 74 21 20 | | (set! |
|00002bc0| 6d 61 74 63 68 65 73 0a | 20 20 20 20 20 20 20 20 |matches.| |
|00002bd0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00002be0| 28 63 6f 6e 73 20 28 6c | 69 73 74 20 74 20 28 73 |(cons (l|ist t (s|
|00002bf0| 74 72 69 6e 67 2d 61 70 | 70 65 6e 64 20 28 6f 73 |tring-ap|pend (os|
|00002c00| 2d 67 65 74 77 64 29 20 | 22 2f 22 20 69 29 29 0a |-getwd) |"/" i)).|
|00002c10| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00002c20| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 6d 61 | | ma|
|00002c30| 74 63 68 65 73 29 29 0a | 20 20 20 20 20 20 20 20 |tches)).| |
|00002c40| 20 20 20 20 20 20 29 3b | 77 68 65 6e 0a 20 20 20 | );|when. |
|00002c50| 20 20 20 20 20 20 20 20 | 20 29 3b 0a 20 20 20 20 | | );. |
|00002c60| 20 20 20 20 20 20 29 3b | 6c 61 6d 62 64 61 0a 20 | );|lambda. |
|00002c70| 20 20 20 20 20 20 20 29 | 3b 74 72 61 76 65 72 73 | )|;travers|
|00002c80| 65 0a 20 20 20 20 20 20 | 20 20 28 73 65 74 21 20 |e. | (set! |
|00002c90| 6d 61 74 63 68 65 73 20 | 28 73 6f 72 74 20 6d 61 |matches |(sort ma|
|00002ca0| 74 63 68 65 73 20 28 6c | 61 6d 62 64 61 20 28 61 |tches (l|ambda (a|
|00002cb0| 20 62 29 20 28 3e 20 28 | 63 61 72 20 61 29 20 28 | b) (> (|car a) (|
|00002cc0| 63 61 72 20 62 29 29 29 | 29 29 0a 20 20 20 20 20 |car b)))|)). |
|00002cd0| 20 20 20 28 64 6f 6c 69 | 73 74 20 28 69 20 6d 61 | (doli|st (i ma|
|00002ce0| 74 63 68 65 73 29 0a 20 | 20 20 20 20 20 20 20 20 |tches). | |
|00002cf0| 20 20 20 28 66 6f 72 6d | 61 74 20 23 74 20 22 7e | (form|at #t "~|
|00002d00| 61 20 20 20 20 20 20 7e | 61 7e 25 22 20 28 63 61 |a ~|a~%" (ca|
|00002d10| 64 72 20 69 29 20 28 6f | 73 2d 74 69 6d 65 73 74 |dr i) (o|s-timest|
|00002d20| 72 69 6e 67 20 28 63 61 | 72 20 69 29 29 29 29 0a |ring (ca|r i)))).|
|00002d30| 20 20 20 20 20 20 6d 61 | 74 63 68 65 73 29 3b 6c | ma|tches);l|
|00002d40| 65 74 0a 20 20 20 20 29 | 3b 66 69 6c 65 73 77 68 |et. )|;fileswh|
|00002d50| 65 6e 0a 5c 65 6e 64 7b | 76 65 72 62 61 74 69 6d |en.\end{|verbatim|
|00002d60| 7d 0a 0a 5c 73 75 62 73 | 65 63 74 69 6f 6e 7b 45 |}..\subs|ection{E|
|00002d70| 78 61 6d 70 6c 65 20 2d | 20 63 68 65 63 6b 73 75 |xample -| checksu|
|00002d80| 6d 64 69 72 7d 0a 0a 54 | 68 69 73 20 73 68 65 6c |mdir}..T|his shel|
|00002d90| 6c 20 77 61 6c 6b 73 20 | 64 6f 77 6e 20 74 68 65 |l walks |down the|
|00002da0| 20 64 69 72 65 63 74 6f | 72 79 20 74 72 65 65 2c | directo|ry tree,|
|00002db0| 20 63 61 6c 6c 73 20 61 | 20 63 68 65 63 6b 73 75 | calls a| checksu|
|00002dc0| 6d 20 66 75 6e 63 74 69 | 6f 6e 20 66 6f 72 20 0a |m functi|on for .|
|00002dd0| 65 61 63 68 20 66 69 6c | 65 2c 20 73 61 76 65 73 |each fil|e, saves|
|00002de0| 20 74 68 69 73 20 63 68 | 65 63 6b 73 75 6d 20 69 | this ch|ecksum i|
|00002df0| 6e 20 61 20 6c 69 73 74 | 2c 20 63 6f 6d 70 61 72 |n a list|, compar|
|00002e00| 65 73 20 74 68 65 20 63 | 68 65 63 6b 73 75 6d 0a |es the c|hecksum.|
|00002e10| 74 6f 20 61 20 70 72 65 | 76 69 6f 75 73 20 6c 69 |to a pre|vious li|
|00002e20| 73 74 2c 20 61 6e 64 20 | 73 65 6e 64 73 20 74 68 |st, and |sends th|
|00002e30| 65 20 75 73 65 72 20 6d | 61 69 6c 20 72 65 70 6f |e user m|ail repo|
|00002e40| 72 74 69 6e 67 20 61 6e | 79 0a 61 6c 74 65 72 65 |rting an|y.altere|
|00002e50| 64 2c 20 6e 65 77 2c 20 | 6f 72 20 64 65 6c 65 74 |d, new, |or delet|
|00002e60| 65 64 20 66 69 6c 65 73 | 2e 0a 54 68 69 73 20 73 |ed files|..This s|
|00002e70| 68 65 6c 6c 20 69 6c 6c | 75 73 74 72 61 74 65 73 |hell ill|ustrates|
|00002e80| 20 73 6f 6d 65 20 61 64 | 64 69 74 69 6f 6e 61 6c | some ad|ditional|
|00002e90| 20 73 68 65 6c 6c 20 66 | 75 6e 63 74 69 6f 6e 73 | shell f|unctions|
|00002ea0| 2c 20 0a 66 6f 72 20 65 | 78 61 6d 70 6c 65 2c 20 |, .for e|xample, |
|00002eb0| 70 6f 70 65 6e 20 69 73 | 20 63 61 6c 6c 65 64 20 |popen is| called |
|00002ec0| 74 6f 20 73 65 6e 64 20 | 61 20 6d 61 69 6c 20 72 |to send |a mail r|
|00002ed0| 65 70 6f 72 74 20 74 6f | 20 74 68 65 20 75 73 65 |eport to| the use|
|00002ee0| 72 2e 0a 0a 4d 6f 72 65 | 20 69 6d 70 6f 72 74 61 |r...More| importa|
|00002ef0| 6e 74 6c 79 2c 20 74 68 | 69 73 20 73 68 65 6c 6c |ntly, th|is shell|
|00002f00| 20 64 79 6e 61 6d 69 63 | 61 6c 6c 79 20 6c 6f 61 | dynamic|ally loa|
|00002f10| 64 73 20 61 20 43 20 66 | 75 6e 63 74 69 6f 6e 0a |ds a C f|unction.|
|00002f20| 5c 76 65 72 62 7c 63 68 | 65 63 6b 73 75 6d 28 29 |\verb|ch|ecksum()|
|00002f30| 7c 20 77 68 69 63 68 20 | 63 6f 6d 70 75 74 65 73 || which |computes|
|00002f40| 20 74 68 65 20 66 69 6c | 65 20 63 68 65 63 6b 73 | the fil|e checks|
|00002f50| 75 6d 2e 20 20 7b 5c 65 | 6d 0a 53 69 6e 63 65 20 |um. {\e|m.Since |
|00002f60| 74 68 65 20 63 68 65 63 | 6b 73 75 6d 20 69 73 20 |the chec|ksum is |
|00002f70| 74 68 65 6e 20 69 6e 74 | 72 69 6e 73 69 63 20 74 |then int|rinsic t|
|00002f80| 6f 20 74 68 65 20 73 68 | 65 6c 6c 2c 20 0a 69 74 |o the sh|ell, .it|
|00002f90| 20 72 75 6e 73 20 6d 75 | 63 68 20 66 61 73 74 65 | runs mu|ch faste|
|00002fa0| 72 20 74 68 61 6e 20 61 | 6e 20 65 78 74 65 72 6e |r than a|n extern|
|00002fb0| 61 6c 20 70 72 6f 63 65 | 73 73 20 77 68 69 63 68 |al proce|ss which|
|00002fc0| 20 77 6f 75 6c 64 20 6e | 65 65 64 0a 74 6f 20 62 | would n|eed.to b|
|00002fd0| 65 20 69 6e 76 6f 6b 65 | 64 20 66 6f 72 20 65 61 |e invoke|d for ea|
|00002fe0| 63 68 20 66 69 6c 65 2e | 7d 0a 44 65 70 65 6e 64 |ch file.|}.Depend|
|00002ff0| 69 6e 67 20 6f 6e 20 74 | 68 65 20 73 69 7a 65 20 |ing on t|he size |
|00003000| 6f 66 20 74 68 65 20 64 | 69 72 65 63 74 6f 72 79 |of the d|irectory|
|00003010| 2c 20 79 6f 75 20 6d 61 | 79 20 6e 65 65 64 20 74 |, you ma|y need t|
|00003020| 6f 20 0a 75 73 65 20 61 | 20 6c 61 72 67 65 72 20 |o .use a| larger |
|00003030| 68 65 61 70 20 73 69 7a | 65 20 69 6e 20 45 6c 6b |heap siz|e in Elk|
|00003040| 20 69 6e 20 6f 72 64 65 | 72 20 74 6f 20 72 75 6e | in orde|r to run|
|00003050| 20 74 68 69 73 20 73 68 | 65 6c 6c 2e 0a 0a 5c 62 | this sh|ell...\b|
|00003060| 65 67 69 6e 7b 76 65 72 | 62 61 74 69 6d 7d 0a 23 |egin{ver|batim}.#|
|00003070| 21 20 2f 75 73 72 2f 6c | 6f 63 61 6c 2f 70 75 62 |! /usr/l|ocal/pub|
|00003080| 2f 62 69 6e 2f 65 6c 6b | 0a 3b 3b 20 63 68 65 63 |/bin/elk|.;; chec|
|00003090| 6b 73 75 6d 20 63 68 65 | 63 6b 20 61 20 73 70 65 |ksum che|ck a spe|
|000030a0| 63 69 66 69 65 64 20 64 | 69 72 65 63 74 6f 72 79 |cified d|irectory|
|000030b0| 20 74 72 65 65 3a 0a 3b | 3b 20 63 68 65 63 6b 73 | tree:.;|; checks|
|000030c0| 75 6d 73 20 61 6c 6c 20 | 66 69 6c 65 73 2c 20 77 |ums all |files, w|
|000030d0| 72 69 74 65 73 20 72 65 | 73 75 6c 74 73 20 74 6f |rites re|sults to|
|000030e0| 20 61 20 66 69 6c 65 20 | 63 68 65 63 6b 73 75 6d | a file |checksum|
|000030f0| 2d 6c 69 73 74 2e 65 2c | 0a 3b 3b 20 6c 6f 6f 6b |-list.e,|.;; look|
|00003100| 73 20 66 6f 72 20 6d 61 | 74 63 68 69 6e 67 20 6e |s for ma|tching n|
|00003110| 61 6d 65 73 20 69 6e 20 | 70 72 65 76 69 6f 75 73 |ames in |previous|
|00003120| 20 76 65 72 73 69 6f 6e | 20 6f 66 20 74 68 65 20 | version| of the |
|00003130| 73 61 6d 65 20 66 69 6c | 65 2c 0a 3b 3b 20 72 65 |same fil|e,.;; re|
|00003140| 70 6f 72 74 73 20 61 6e | 79 20 63 68 61 6e 67 65 |ports an|y change|
|00003150| 64 20 63 68 65 63 6b 73 | 75 6d 73 2c 20 64 65 6c |d checks|ums, del|
|00003160| 65 74 65 64 20 66 69 6c | 65 73 2c 20 6f 72 20 6e |eted fil|es, or n|
|00003170| 65 77 20 66 69 6c 65 73 | 2e 0a 3b 3b 0a 3b 3b 20 |ew files|..;;.;; |
|00003180| 54 68 65 20 66 69 6c 65 | 20 63 68 65 63 6b 73 75 |The file| checksu|
|00003190| 6d 2d 6c 69 73 74 2e 65 | 20 69 73 20 6b 65 70 74 |m-list.e| is kept|
|000031a0| 20 69 6e 20 74 68 65 20 | 74 6f 70 20 64 69 72 65 | in the |top dire|
|000031b0| 63 74 6f 72 79 20 6f 66 | 20 74 68 65 20 74 72 65 |ctory of| the tre|
|000031c0| 65 0a 3b 3b 20 61 6e 64 | 20 73 68 6f 75 6c 64 20 |e.;; and| should |
|000031d0| 6e 6f 74 20 62 65 20 64 | 65 6c 65 74 65 64 20 6f |not be d|eleted o|
|000031e0| 72 20 77 72 69 74 65 2d | 70 72 6f 74 65 63 74 65 |r write-|protecte|
|000031f0| 64 2e 0a 0a 28 6c 6f 61 | 64 20 22 63 6c 61 72 67 |d...(loa|d "clarg|
|00003200| 73 2e 65 22 29 20 20 20 | 20 20 20 20 20 20 20 20 |s.e") | |
|00003210| 20 20 20 20 20 20 20 20 | 20 20 20 20 3b 62 69 6e | | ;bin|
|00003220| 64 20 61 72 67 75 6d 65 | 6e 74 73 20 74 6f 20 24 |d argume|nts to $|
|00003230| 31 2c 2e 2e 2e 0a 28 6c | 6f 61 64 20 22 74 72 61 |1,....(l|oad "tra|
|00003240| 76 65 72 73 65 64 69 72 | 2e 65 22 29 0a 0a 28 64 |versedir|.e")..(d|
|00003250| 65 66 69 6e 65 20 63 68 | 65 63 6b 73 75 6d 2d 64 |efine ch|ecksum-d|
|00003260| 69 72 20 22 2f 75 2f 7a | 69 6c 6c 61 2f 63 68 65 |ir "/u/z|illa/che|
|00003270| 63 6b 73 75 6d 2f 22 29 | 0a 28 64 65 66 69 6e 65 |cksum/")|.(define|
|00003280| 20 72 65 70 6f 72 74 2d | 64 65 6c 65 74 65 64 3f | report-|deleted?|
|00003290| 20 23 74 29 0a 0a 28 69 | 66 20 28 6e 6f 74 20 28 | #t)..(i|f (not (|
|000032a0| 62 6f 75 6e 64 3f 20 27 | 63 68 65 63 6b 73 75 6d |bound? '|checksum|
|000032b0| 66 69 6c 65 29 29 20 20 | 20 20 20 20 20 20 3b 6c |file)) | ;l|
|000032c0| 6f 61 64 20 43 20 66 75 | 6e 63 74 69 6f 6e 0a 20 |oad C fu|nction. |
|000032d0| 20 20 20 28 6c 6f 61 64 | 20 28 73 74 72 69 6e 67 | (load| (string|
|000032e0| 2d 61 70 70 65 6e 64 20 | 63 68 65 63 6b 73 75 6d |-append |checksum|
|000032f0| 2d 64 69 72 20 22 63 68 | 65 63 6b 73 75 6d 2e 6f |-dir "ch|ecksum.o|
|00003300| 22 29 29 0a 29 0a 0a 28 | 64 65 66 69 6e 65 20 6f |")).)..(|define o|
|00003310| 6c 64 2d 63 68 65 63 6b | 73 75 6d 2d 6c 69 73 74 |ld-check|sum-list|
|00003320| 20 27 28 29 29 0a 0a 3b | 3b 3b 3b 3b 3b 3b 3b 3b | '())..;|;;;;;;;;|
|00003330| 3b 3b 3b 3b 3b 3b 3b 20 | 68 65 6c 70 65 72 20 66 |;;;;;;; |helper f|
|00003340| 75 6e 63 74 69 6f 6e 73 | 0a 0a 0a 20 20 20 20 20 |unctions|... |
|00003350| 20 20 20 3b 20 77 72 69 | 74 65 20 63 68 65 63 6b | ; wri|te check|
|00003360| 73 75 6d 73 20 74 6f 20 | 66 69 6c 65 0a 20 20 20 |sums to |file. |
|00003370| 20 20 20 20 20 28 64 65 | 66 69 6e 65 20 28 6f 75 | (de|fine (ou|
|00003380| 74 70 75 74 2d 6c 69 73 | 74 20 70 61 74 68 20 63 |tput-lis|t path c|
|00003390| 68 65 63 6b 73 75 6d 2d | 6c 69 73 74 29 0a 20 20 |hecksum-|list). |
|000033a0| 20 20 20 20 20 20 20 20 | 28 63 61 6c 6c 2d 77 69 | |(call-wi|
|000033b0| 74 68 2d 6f 75 74 70 75 | 74 2d 66 69 6c 65 0a 20 |th-outpu|t-file. |
|000033c0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 22 63 68 | | "ch|
|000033d0| 65 63 6b 73 75 6d 2d 6c | 69 73 74 2e 65 22 20 3b |ecksum-l|ist.e" ;|
|000033e0| 20 77 72 69 74 65 20 69 | 6e 20 63 75 72 72 65 6e | write i|n curren|
|000033f0| 74 20 64 69 72 65 63 74 | 6f 72 79 0a 20 20 20 20 |t direct|ory. |
|00003400| 20 20 20 20 20 20 20 20 | 28 6c 61 6d 62 64 61 20 | |(lambda |
|00003410| 28 66 29 0a 20 20 20 20 | 20 20 20 20 20 20 20 20 |(f). | |
|00003420| 20 20 28 66 6f 72 6d 61 | 74 20 66 20 22 28 73 65 | (forma|t f "(se|
|00003430| 74 21 20 6f 6c 64 2d 63 | 68 65 63 6b 73 75 6d 2d |t! old-c|hecksum-|
|00003440| 6c 69 73 74 20 27 28 7e | 25 22 29 0a 20 20 20 20 |list '(~|%"). |
|00003450| 20 20 20 20 20 20 20 20 | 20 20 28 64 6f 6c 69 73 | | (dolis|
|00003460| 74 20 28 69 20 63 68 65 | 63 6b 73 75 6d 2d 6c 69 |t (i che|cksum-li|
|00003470| 73 74 29 0a 20 20 20 20 | 20 20 20 20 20 20 20 20 |st). | |
|00003480| 20 20 20 20 20 20 20 20 | 20 20 28 66 6f 72 6d 61 | | (forma|
|00003490| 74 20 66 20 22 7e 73 7e | 25 22 20 69 29 29 0a 20 |t f "~s~|%" i)). |
|000034a0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 28 66 6f | | (fo|
|000034b0| 72 6d 61 74 20 66 20 22 | 29 29 7e 25 22 29 0a 20 |rmat f "|))~%"). |
|000034c0| 20 20 20 20 20 20 20 20 | 20 20 20 29 0a 20 20 20 | | ). |
|000034d0| 20 20 20 20 20 20 20 29 | 0a 20 20 20 20 20 20 20 | )|. |
|000034e0| 20 29 3b 6f 75 74 70 75 | 74 2d 6c 69 73 74 0a 0a | );outpu|t-list..|
|000034f0| 0a 20 20 20 20 20 20 20 | 20 3b 20 69 66 20 64 69 |. | ; if di|
|00003500| 66 66 65 72 65 6e 63 65 | 73 2c 20 73 65 6e 64 20 |fference|s, send |
|00003510| 6d 61 69 6c 20 61 62 6f | 75 74 20 74 68 65 6d 0a |mail abo|ut them.|
|00003520| 20 20 20 20 20 20 20 20 | 28 64 65 66 69 6e 65 20 | |(define |
|00003530| 28 6d 61 69 6c 2d 72 65 | 70 6f 72 74 20 72 65 70 |(mail-re|port rep|
|00003540| 6f 72 74 20 6e 65 77 66 | 69 6c 65 73 20 6f 6c 64 |ort newf|iles old|
|00003550| 6c 69 73 74 20 6e 65 77 | 6c 69 73 74 29 0a 20 20 |list new|list). |
|00003560| 20 20 20 20 20 20 20 20 | 28 6c 65 74 20 28 28 66 | |(let ((f|
|00003570| 20 28 6f 73 2d 70 6f 70 | 65 6e 0a 20 20 20 20 20 | (os-pop|en. |
|00003580| 20 20 20 20 20 20 20 20 | 20 20 20 20 28 66 6f 72 | | (for|
|00003590| 6d 61 74 20 23 66 20 22 | 2f 75 73 72 2f 75 63 62 |mat #f "|/usr/ucb|
|000035a0| 2f 6d 61 69 6c 20 2d 73 | 20 43 48 45 43 4b 53 55 |/mail -s| CHECKSU|
|000035b0| 4d 20 7e 61 22 20 28 6f | 73 2d 67 65 74 65 6e 76 |M ~a" (o|s-getenv|
|000035c0| 20 22 55 53 45 52 22 29 | 29 0a 20 20 20 20 20 20 | "USER")|). |
|000035d0| 20 20 20 20 20 20 20 20 | 20 20 20 22 77 22 29 29 | | "w"))|
|000035e0| 29 0a 20 20 20 20 20 20 | 20 20 20 20 20 20 28 66 |). | (f|
|000035f0| 6f 72 6d 61 74 20 66 20 | 22 63 68 65 63 6b 73 75 |ormat f |"checksu|
|00003600| 6d 20 61 74 20 7e 61 7e | 25 22 20 28 6f 73 2d 74 |m at ~a~|%" (os-t|
|00003610| 69 6d 65 73 74 72 69 6e | 67 20 28 6f 73 2d 63 75 |imestrin|g (os-cu|
|00003620| 72 74 69 6d 65 29 29 29 | 0a 20 20 20 20 20 20 20 |rtime)))|. |
|00003630| 20 20 20 20 20 28 64 6f | 6c 69 73 74 20 28 69 20 | (do|list (i |
|00003640| 72 65 70 6f 72 74 29 20 | 28 66 6f 72 6d 61 74 20 |report) |(format |
|00003650| 66 20 22 7e 61 22 20 69 | 29 29 0a 20 20 20 20 20 |f "~a" i|)). |
|00003660| 20 20 20 20 20 20 20 28 | 69 66 20 72 65 70 6f 72 | (|if repor|
|00003670| 74 2d 64 65 6c 65 74 65 | 64 3f 0a 20 20 20 20 20 |t-delete|d?. |
|00003680| 20 20 20 20 20 20 20 20 | 20 28 64 6f 6c 69 73 74 | | (dolist|
|00003690| 20 28 69 20 6f 6c 64 6c | 69 73 74 29 0a 20 20 20 | (i oldl|ist). |
|000036a0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 28 77 | | (w|
|000036b0| 68 65 6e 20 28 6e 6f 74 | 20 28 61 73 73 6f 63 20 |hen (not| (assoc |
|000036c0| 28 63 61 72 20 69 29 20 | 6e 65 77 6c 69 73 74 29 |(car i) |newlist)|
|000036d0| 29 0a 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |). | |
|000036e0| 20 20 20 20 20 20 20 28 | 66 6f 72 6d 61 74 20 23 | (|format #|
|000036f0| 74 20 22 44 45 4c 45 54 | 45 44 20 7e 61 7e 25 22 |t "DELET|ED ~a~%"|
|00003700| 20 28 63 61 72 20 69 29 | 29 20 3b 20 6e 6f 74 20 | (car i)|) ; not |
|00003710| 72 65 70 6f 72 74 65 64 | 20 62 65 66 6f 72 65 0a |reported| before.|
|00003720| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00003730| 20 20 20 20 20 28 66 6f | 72 6d 61 74 20 66 20 22 | (fo|rmat f "|
|00003740| 44 45 4c 45 54 45 44 20 | 7e 61 7e 25 22 20 28 63 |DELETED |~a~%" (c|
|00003750| 61 72 20 69 29 29 29 0a | 20 20 20 20 20 20 20 20 |ar i))).| |
|00003760| 20 20 20 20 29 29 0a 20 | 20 20 20 20 20 20 20 20 | )). | |
|00003770| 20 20 20 28 64 6f 6c 69 | 73 74 20 28 69 20 6e 65 | (doli|st (i ne|
|00003780| 77 66 69 6c 65 73 29 20 | 28 66 6f 72 6d 61 74 20 |wfiles) |(format |
|00003790| 66 20 22 7e 61 22 20 69 | 29 29 0a 20 20 20 20 20 |f "~a" i|)). |
|000037a0| 20 20 20 20 20 20 20 28 | 6f 73 2d 70 63 6c 6f 73 | (|os-pclos|
|000037b0| 65 20 66 29 0a 20 20 20 | 20 20 20 20 20 20 20 29 |e f). | )|
|000037c0| 0a 20 20 20 20 20 20 20 | 20 29 3b 6d 61 69 6c 2d |. | );mail-|
|000037d0| 72 65 70 6f 72 74 0a 0a | 0a 28 64 65 66 69 6e 65 |report..|.(define|
|000037e0| 20 28 63 68 65 63 6b 73 | 75 6d 20 70 61 74 68 29 | (checks|um path)|
|000037f0| 0a 20 20 28 73 65 74 21 | 20 73 68 65 6c 6c 2d 76 |. (set!| shell-v|
|00003800| 65 72 62 6f 73 65 3f 20 | 23 66 29 0a 20 20 28 6f |erbose? |#f). (o|
|00003810| 73 2d 63 68 64 69 72 20 | 70 61 74 68 29 0a 20 20 |s-chdir |path). |
|00003820| 28 69 66 20 28 66 69 6c | 65 2d 65 78 69 73 74 73 |(if (fil|e-exists|
|00003830| 3f 20 22 63 68 65 63 6b | 73 75 6d 2d 6c 69 73 74 |? "check|sum-list|
|00003840| 2e 65 22 29 0a 20 20 20 | 20 20 20 28 6c 6f 61 64 |.e"). | (load|
|00003850| 20 22 63 68 65 63 6b 73 | 75 6d 2d 6c 69 73 74 2e | "checks|um-list.|
|00003860| 65 22 29 29 0a 20 20 28 | 6c 65 74 20 28 28 63 68 |e")). (|let ((ch|
|00003870| 65 63 6b 73 75 6d 2d 6c | 69 73 74 20 27 28 29 29 |ecksum-l|ist '())|
|00003880| 0a 20 20 20 20 20 20 20 | 20 28 72 65 70 6f 72 74 |. | (report|
|00003890| 20 27 28 29 29 0a 20 20 | 20 20 20 20 20 20 28 6e | '()). | (n|
|000038a0| 65 77 66 69 6c 65 73 20 | 27 28 29 29 0a 20 20 20 |ewfiles |'()). |
|000038b0| 20 20 20 20 20 28 64 65 | 6c 65 74 65 64 2d 66 69 | (de|leted-fi|
|000038c0| 6c 65 73 20 27 28 29 29 | 0a 20 20 20 20 20 20 20 |les '())|. |
|000038d0| 20 29 0a 20 20 20 20 28 | 74 72 61 76 65 72 73 65 | ). (|traverse|
|000038e0| 2d 70 20 70 61 74 68 0a | 20 20 20 20 20 20 28 6c |-p path.| (l|
|000038f0| 61 6d 62 64 61 20 28 66 | 29 0a 20 20 20 20 20 20 |ambda (f|). |
|00003900| 20 20 28 6c 65 74 20 28 | 28 63 20 28 63 68 65 63 | (let (|(c (chec|
|00003910| 6b 73 75 6d 66 69 6c 65 | 20 66 29 29 0a 20 20 20 |ksumfile| f)). |
|00003920| 20 20 20 20 20 20 20 20 | 20 20 20 28 61 20 28 61 | | (a (a|
|00003930| 73 73 6f 63 20 66 20 6f | 6c 64 2d 63 68 65 63 6b |ssoc f o|ld-check|
|00003940| 73 75 6d 2d 6c 69 73 74 | 29 29 0a 20 20 20 20 20 |sum-list|)). |
|00003950| 20 20 20 20 20 20 20 20 | 20 29 0a 0a 20 20 20 20 | | ).. |
|00003960| 20 20 20 20 20 20 28 73 | 65 74 21 20 63 68 65 63 | (s|et! chec|
|00003970| 6b 73 75 6d 2d 6c 69 73 | 74 20 28 63 6f 6e 73 20 |ksum-lis|t (cons |
|00003980| 28 6c 69 73 74 20 66 20 | 63 29 20 63 68 65 63 6b |(list f |c) check|
|00003990| 73 75 6d 2d 6c 69 73 74 | 29 29 0a 0a 20 20 20 20 |sum-list|)).. |
|000039a0| 20 20 20 20 20 20 28 63 | 6f 6e 64 0a 0a 20 20 20 | (c|ond.. |
|000039b0| 20 20 20 20 20 20 20 20 | 28 61 20 28 69 66 20 28 | |(a (if (|
|000039c0| 6e 6f 74 20 28 65 71 75 | 61 6c 3f 20 63 20 28 63 |not (equ|al? c (c|
|000039d0| 61 64 72 20 61 29 29 29 | 0a 20 20 20 20 20 20 20 |adr a)))|. |
|000039e0| 20 20 20 20 20 20 20 20 | 20 20 20 28 6c 65 74 20 | | (let |
|000039f0| 28 28 6d 73 67 0a 20 20 | 20 20 20 20 20 20 20 20 |((msg. | |
|00003a00| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 28 | | (|
|00003a10| 66 6f 72 6d 61 74 20 23 | 66 20 22 43 48 45 43 4b |format #|f "CHECK|
|00003a20| 53 55 4d 20 44 49 46 46 | 45 52 53 20 7e 61 20 7e |SUM DIFF|ERS ~a ~|
|00003a30| 61 20 7e 61 7e 25 22 0a | 20 20 20 20 20 20 20 20 |a ~a~%".| |
|00003a40| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00003a50| 20 20 20 20 20 20 20 20 | 20 66 20 63 20 28 63 61 | | f c (ca|
|00003a60| 64 72 20 61 29 29 29 29 | 0a 20 20 20 20 20 20 20 |dr a))))|. |
|00003a70| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 28 70 72 | | (pr|
|00003a80| 69 6e 74 20 6d 73 67 29 | 0a 20 20 20 20 20 20 20 |int msg)|. |
|00003a90| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 28 73 65 | | (se|
|00003aa0| 74 21 20 72 65 70 6f 72 | 74 20 28 63 6f 6e 73 20 |t! repor|t (cons |
|00003ab0| 6d 73 67 20 72 65 70 6f | 72 74 29 29 0a 20 20 20 |msg repo|rt)). |
|00003ac0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 29 | | )|
|00003ad0| 0a 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 29 |. | )|
|00003ae0| 0a 20 20 20 20 20 20 20 | 20 20 20 20 29 3b 61 0a |. | );a.|
|00003af0| 0a 20 20 20 20 20 20 20 | 20 20 20 20 28 28 6e 6f |. | ((no|
|00003b00| 74 20 61 29 0a 20 20 20 | 20 20 20 20 20 20 20 20 |t a). | |
|00003b10| 20 28 6c 65 74 20 28 28 | 6d 73 67 20 28 66 6f 72 | (let ((|msg (for|
|00003b20| 6d 61 74 20 23 66 20 22 | 7e 61 20 49 53 20 4e 45 |mat #f "|~a IS NE|
|00003b30| 57 7e 25 22 20 66 29 29 | 29 0a 20 20 20 20 20 20 |W~%" f))|). |
|00003b40| 20 20 20 20 20 20 20 20 | 28 70 72 69 6e 74 20 6d | |(print m|
|00003b50| 73 67 29 0a 20 20 20 20 | 20 20 20 20 20 20 20 20 |sg). | |
|00003b60| 20 20 28 73 65 74 21 20 | 6e 65 77 66 69 6c 65 73 | (set! |newfiles|
|00003b70| 20 28 63 6f 6e 73 20 6d | 73 67 20 6e 65 77 66 69 | (cons m|sg newfi|
|00003b80| 6c 65 73 29 29 0a 20 20 | 20 20 20 20 20 20 20 20 |les)). | |
|00003b90| 20 20 29 29 0a 0a 20 20 | 20 20 20 20 20 20 20 20 | )).. | |
|00003ba0| 29 3b 63 6f 6e 64 0a 20 | 20 20 20 20 20 20 20 29 |);cond. | )|
|00003bb0| 3b 6c 65 74 0a 20 20 20 | 20 20 20 29 3b 6c 61 6d |;let. | );lam|
|00003bc0| 62 64 61 0a 20 20 20 20 | 29 3b 74 72 61 76 65 72 |bda. |);traver|
|00003bd0| 73 65 0a 0a 20 20 20 20 | 28 6f 75 74 70 75 74 2d |se.. |(output-|
|00003be0| 6c 69 73 74 20 70 61 74 | 68 20 63 68 65 63 6b 73 |list pat|h checks|
|00003bf0| 75 6d 2d 6c 69 73 74 29 | 0a 0a 20 20 20 20 28 69 |um-list)|.. (i|
|00003c00| 66 20 28 3e 20 28 6c 65 | 6e 67 74 68 20 72 65 70 |f (> (le|ngth rep|
|00003c10| 6f 72 74 29 20 30 29 0a | 20 20 20 20 20 20 20 20 |ort) 0).| |
|00003c20| 28 6d 61 69 6c 2d 72 65 | 70 6f 72 74 20 72 65 70 |(mail-re|port rep|
|00003c30| 6f 72 74 20 6e 65 77 66 | 69 6c 65 73 20 6f 6c 64 |ort newf|iles old|
|00003c40| 2d 63 68 65 63 6b 73 75 | 6d 2d 6c 69 73 74 20 63 |-checksu|m-list c|
|00003c50| 68 65 63 6b 73 75 6d 2d | 6c 69 73 74 29 29 0a 20 |hecksum-|list)). |
|00003c60| 20 29 3b 6c 65 74 0a 29 | 3b 63 68 65 63 6b 73 75 | );let.)|;checksu|
|00003c70| 6d 0a 0a 28 63 68 65 63 | 6b 73 75 6d 20 24 31 29 |m..(chec|ksum $1)|
|00003c80| 0a 28 65 78 69 74 20 30 | 29 0a 5c 65 6e 64 7b 76 |.(exit 0|).\end{v|
|00003c90| 65 72 62 61 74 69 6d 7d | 0a 0a 54 68 65 20 43 20 |erbatim}|..The C |
|00003ca0| 66 75 6e 63 74 69 6f 6e | 20 6c 6f 61 64 65 64 20 |function| loaded |
|00003cb0| 62 79 20 74 68 65 20 63 | 68 65 63 6b 73 75 6d 20 |by the c|hecksum |
|00003cc0| 73 68 65 6c 6c 20 69 73 | 20 6c 69 73 74 65 64 0a |shell is| listed.|
|00003cd0| 69 6e 20 74 68 65 20 74 | 75 74 6f 72 69 61 6c 20 |in the t|utorial |
|00003ce0| 73 65 63 74 69 6f 6e 20 | 6f 6e 20 74 68 65 20 66 |section |on the f|
|00003cf0| 6f 72 65 69 67 6e 20 66 | 75 6e 63 74 69 6f 6e 20 |oreign f|unction |
|00003d00| 69 6e 74 65 72 66 61 63 | 65 2e 0a 0a 0a 5c 73 75 |interfac|e....\su|
|00003d10| 62 73 65 63 74 69 6f 6e | 7b 44 69 66 66 65 72 65 |bsection|{Differe|
|00003d20| 6e 74 20 41 72 63 68 69 | 74 65 63 74 75 72 65 73 |nt Archi|tectures|
|00003d30| 2c 20 53 61 6d 65 20 46 | 69 6c 65 20 53 79 73 74 |, Same F|ile Syst|
|00003d40| 65 6d 7d 0a 0a 54 68 65 | 20 55 6e 69 78 20 73 68 |em}..The| Unix sh|
|00003d50| 65 6c 6c 20 69 6e 74 65 | 72 70 72 65 74 65 72 20 |ell inte|rpreter |
|00003d60| 6d 65 63 68 61 6e 69 73 | 6d 20 73 70 65 63 69 66 |mechanis|m specif|
|00003d70| 69 65 73 20 61 6e 20 61 | 62 73 6f 6c 75 74 65 20 |ies an a|bsolute |
|00003d80| 70 61 74 68 2c 20 65 2e | 67 2e 2c 0a 5c 62 65 67 |path, e.|g.,.\beg|
|00003d90| 69 6e 7b 76 65 72 62 61 | 74 69 6d 7d 0a 20 20 20 |in{verba|tim}. |
|00003da0| 20 23 21 20 2f 75 73 72 | 2f 6c 6f 63 61 6c 2f 62 | #! /usr|/local/b|
|00003db0| 69 6e 2f 65 6c 6b 0a 5c | 65 6e 64 7b 76 65 72 62 |in/elk.\|end{verb|
|00003dc0| 61 74 69 6d 7d 0a 54 68 | 69 73 20 63 61 6e 20 62 |atim}.Th|is can b|
|00003dd0| 65 20 61 20 70 72 6f 62 | 6c 65 6d 20 69 66 20 6d |e a prob|lem if m|
|00003de0| 61 63 68 69 6e 65 73 20 | 6f 66 20 73 65 76 65 72 |achines |of sever|
|00003df0| 61 6c 20 64 69 66 66 65 | 72 65 6e 74 20 61 72 63 |al diffe|rent arc|
|00003e00| 68 69 74 65 63 74 75 72 | 65 73 0a 73 68 61 72 65 |hitectur|es.share|
|00003e10| 20 6f 6e 65 20 66 69 6c | 65 6e 61 6d 65 20 73 70 | one fil|ename sp|
|00003e20| 61 63 65 2d 2d 2d 61 20 | 73 68 65 6c 6c 20 77 68 |ace---a |shell wh|
|00003e30| 69 63 68 20 75 73 65 73 | 20 74 68 65 20 70 61 74 |ich uses| the pat|
|00003e40| 68 20 66 6f 72 20 6f 6e | 65 20 0a 61 72 63 68 69 |h for on|e .archi|
|00003e50| 74 65 63 74 75 72 65 20 | 77 69 6c 6c 20 66 61 69 |tecture |will fai|
|00003e60| 6c 20 74 6f 20 72 75 6e | 20 6f 6e 20 6f 74 68 65 |l to run| on othe|
|00003e70| 72 20 61 72 63 68 69 74 | 65 63 74 75 72 65 73 2e |r archit|ectures.|
|00003e80| 0a 49 64 65 61 6c 6c 79 | 2c 20 74 68 65 20 62 69 |.Ideally|, the bi|
|00003e90| 6e 20 64 69 72 65 63 74 | 6f 72 79 20 63 6f 6e 74 |n direct|ory cont|
|00003ea0| 61 69 6e 69 6e 67 20 45 | 6c 6b 20 73 68 6f 75 6c |aining E|lk shoul|
|00003eb0| 64 20 68 61 76 65 20 74 | 68 65 20 73 61 6d 65 20 |d have t|he same |
|00003ec0| 6e 61 6d 65 0a 6f 6e 20 | 65 61 63 68 20 6d 61 63 |name.on |each mac|
|00003ed0| 68 69 6e 65 20 62 75 74 | 20 73 68 6f 75 6c 64 20 |hine but| should |
|00003ee0| 72 65 66 65 72 20 74 6f | 20 64 69 66 66 65 72 65 |refer to| differe|
|00003ef0| 6e 74 20 61 72 65 61 73 | 0a 66 6f 72 20 65 61 63 |nt areas|.for eac|
|00003f00| 68 20 61 72 63 68 69 74 | 65 63 74 75 72 65 2e 0a |h archit|ecture..|
|00003f10| 49 66 20 74 68 69 73 20 | 69 73 20 6e 6f 74 20 70 |If this |is not p|
|00003f20| 6f 73 73 69 62 6c 65 2c | 20 74 68 65 20 66 6f 6c |ossible,| the fol|
|00003f30| 6c 6f 77 69 6e 67 20 68 | 6f 72 72 6f 72 20 63 61 |lowing h|orror ca|
|00003f40| 6e 20 70 72 65 66 61 63 | 65 20 61 6e 20 45 6c 6b |n prefac|e an Elk|
|00003f50| 0a 73 68 65 6c 6c 20 66 | 69 6c 65 20 69 6e 74 65 |.shell f|ile inte|
|00003f60| 6e 64 65 64 20 74 6f 20 | 72 75 6e 20 6f 6e 20 61 |nded to |run on a|
|00003f70| 6e 79 20 61 72 63 68 69 | 74 65 63 74 75 72 65 3a |ny archi|tecture:|
|00003f80| 0a 5c 62 65 67 69 6e 7b | 76 65 72 62 61 74 69 6d |.\begin{|verbatim|
|00003f90| 7d 0a 20 20 20 20 23 21 | 2f 62 69 6e 2f 63 73 68 |}. #!|/bin/csh|
|00003fa0| 20 2d 66 0a 20 20 20 20 | 3b 65 78 65 63 20 24 7b | -f. |;exec ${|
|00003fb0| 45 4c 4b 42 49 4e 7d 2f | 65 6c 6b 20 24 30 20 24 |ELKBIN}/|elk $0 $|
|00003fc0| 2a 0a 20 20 20 20 28 64 | 65 66 69 6e 65 20 2e 2e |*. (d|efine ..|
|00003fd0| 2e 2e 20 3b 20 65 6c 6b | 20 73 68 65 6c 6c 20 63 |.. ; elk| shell c|
|00003fe0| 6f 6d 6d 61 6e 64 73 20 | 66 6f 6c 6c 6f 77 0a 5c |ommands |follow.\|
|00003ff0| 65 6e 64 7b 76 65 72 62 | 61 74 69 6d 7d 0a 45 4c |end{verb|atim}.EL|
|00004000| 4b 42 49 4e 20 69 73 20 | 61 20 73 68 65 6c 6c 20 |KBIN is |a shell |
|00004010| 76 61 72 69 61 62 6c 65 | 20 73 65 74 20 74 6f 20 |variable| set to |
|00004020| 74 68 65 20 64 69 72 65 | 63 74 6f 72 79 20 63 6f |the dire|ctory co|
|00004030| 6e 74 61 69 6e 69 6e 67 | 20 65 6c 6b 20 6f 6e 0a |ntaining| elk on.|
|00004040| 65 61 63 68 20 61 72 63 | 68 69 74 65 63 74 75 72 |each arc|hitectur|
|00004050| 65 2e 20 20 4e 6f 74 65 | 20 74 68 61 74 20 74 68 |e. Note| that th|
|00004060| 65 20 73 65 6d 69 63 6f | 6c 6f 6e 20 69 73 20 6e |e semico|lon is n|
|00004070| 65 63 65 73 73 61 72 79 | 2d 2d 74 68 69 73 20 68 |ecessary|--this h|
|00004080| 65 61 64 65 72 0a 69 73 | 20 72 65 61 64 20 74 77 |eader.is| read tw|
|00004090| 69 63 65 3a 20 6f 6e 63 | 65 20 62 79 20 63 73 68 |ice: onc|e by csh|
|000040a0| 2c 20 61 6e 64 20 6f 6e | 63 65 20 62 79 20 65 6c |, and on|ce by el|
|000040b0| 6b 2e 0a 0a 5c 73 75 62 | 73 65 63 74 69 6f 6e 7b |k...\sub|section{|
|000040c0| 6f 73 2d 20 52 6f 75 74 | 69 6e 65 73 7d 0a 0a 53 |os- Rout|ines}..S|
|000040d0| 68 65 6c 6c 20 72 65 6c | 65 61 74 65 64 20 66 75 |hell rel|eated fu|
|000040e0| 6e 63 74 69 6f 6e 73 20 | 61 72 65 20 63 6f 6e 73 |nctions |are cons|
|000040f0| 69 73 74 65 6e 74 6c 79 | 20 6e 61 6d 65 64 20 77 |istently| named w|
|00004100| 69 74 68 20 74 68 65 20 | 70 72 65 66 69 78 20 5c |ith the |prefix \|
|00004110| 76 65 72 62 7c 6f 73 2d | 7c 0a 28 72 65 63 61 6c |verb|os-||.(recal|
|00004120| 6c 20 74 68 61 74 20 79 | 6f 75 20 63 61 6e 20 65 |l that y|ou can e|
|00004130| 61 73 69 6c 79 20 72 65 | 6e 61 6d 65 20 66 75 6e |asily re|name fun|
|00004140| 63 74 69 6f 6e 73 20 69 | 6e 20 73 63 68 65 6d 65 |ctions i|n scheme|
|00004150| 29 2e 0a 54 68 65 20 63 | 6f 6d 6d 61 6e 64 20 5c |)..The c|ommand \|
|00004160| 76 65 72 62 7c 28 61 70 | 72 6f 70 6f 73 20 22 6f |verb|(ap|ropos "o|
|00004170| 73 2d 22 29 7c 20 70 72 | 69 6e 74 73 20 61 20 6c |s-")| pr|ints a l|
|00004180| 69 73 74 20 6f 66 20 74 | 68 65 73 65 20 66 75 6e |ist of t|hese fun|
|00004190| 63 74 69 6f 6e 73 3a 0a | 0a 5c 62 65 67 69 6e 7b |ctions:.|.\begin{|
|000041a0| 76 65 72 62 61 74 69 6d | 7d 0a 0a 6f 73 2d 66 6f |verbatim|}..os-fo|
|000041b0| 70 65 6e 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |pen | |
|000041c0| 20 20 20 3b 20 62 75 66 | 66 65 72 65 64 20 69 2f | ; buf|fered i/|
|000041d0| 6f 20 2d 20 73 65 65 20 | 66 6f 70 65 6e 28 33 29 |o - see |fopen(3)|
|000041e0| 0a 6f 73 2d 66 63 6c 6f | 73 65 0a 6f 73 2d 66 73 |.os-fclo|se.os-fs|
|000041f0| 65 65 6b 0a 6f 73 2d 66 | 74 65 6c 6c 0a 6f 73 2d |eek.os-f|tell.os-|
|00004200| 66 72 65 61 64 0a 6f 73 | 2d 66 77 72 69 74 65 0a |fread.os|-fwrite.|
|00004210| 0a 6f 73 2d 73 68 20 20 | 20 20 20 20 20 20 20 20 |.os-sh | |
|00004220| 20 20 20 20 20 20 20 20 | 20 3b 20 73 61 6d 65 20 | | ; same |
|00004230| 61 73 20 74 68 65 20 45 | 6c 6b 20 27 73 79 73 74 |as the E|lk 'syst|
|00004240| 65 6d 27 20 66 75 6e 63 | 74 69 6f 6e 0a 6f 73 2d |em' func|tion.os-|
|00004250| 63 73 68 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |csh | |
|00004260| 20 20 20 20 20 3b 20 6c | 69 6b 65 20 6f 73 2d 73 | ; l|ike os-s|
|00004270| 68 2c 20 62 75 74 20 75 | 73 65 73 20 63 73 68 0a |h, but u|ses csh.|
|00004280| 0a 28 6f 73 2d 65 78 65 | 63 20 22 63 6d 64 22 29 |.(os-exe|c "cmd")|
|00004290| 20 20 20 20 20 20 20 20 | 20 3b 20 65 78 65 63 75 | | ; execu|
|000042a0| 74 65 73 20 61 20 73 68 | 65 6c 6c 20 63 6f 6d 6d |tes a sh|ell comm|
|000042b0| 61 6e 64 2c 20 72 65 74 | 75 72 6e 73 20 61 0a 20 |and, ret|urns a. |
|000042c0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|000042d0| 20 20 20 20 20 20 20 3b | 20 70 69 64 20 74 68 61 | ;| pid tha|
|000042e0| 74 20 63 61 6e 20 62 65 | 20 70 61 73 73 65 64 20 |t can be| passed |
|000042f0| 74 6f 20 6f 73 2d 77 61 | 69 74 70 69 64 0a 28 6f |to os-wa|itpid.(o|
|00004300| 73 2d 77 61 69 74 70 69 | 64 20 70 69 64 29 20 20 |s-waitpi|d pid) |
|00004310| 20 20 20 20 20 20 3b 20 | 77 61 69 74 20 66 6f 72 | ; |wait for|
|00004320| 20 70 72 6f 63 65 73 73 | 20 6e 75 6d 62 65 72 20 | process| number |
|00004330| 70 69 64 20 74 6f 20 66 | 69 6e 69 73 68 2c 0a 20 |pid to f|inish,. |
|00004340| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00004350| 20 20 20 20 20 20 20 3b | 20 72 65 74 75 72 6e 20 | ;| return |
|00004360| 74 68 65 20 65 78 69 74 | 20 73 74 61 74 75 73 20 |the exit| status |
|00004370| 6f 66 20 74 68 65 20 70 | 72 6f 63 65 73 73 2e 0a |of the p|rocess..|
|00004380| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00004390| 20 20 20 20 20 20 20 20 | 3b 20 4e 6f 74 65 2d 74 | |; Note-t|
|000043a0| 68 65 20 61 72 67 75 6d | 65 6e 74 73 20 61 72 65 |he argum|ents are|
|000043b0| 20 6e 6f 74 20 74 68 65 | 20 73 61 6d 65 20 61 73 | not the| same as|
|000043c0| 20 77 61 69 74 70 69 64 | 28 33 29 2e 0a 0a 6f 73 | waitpid|(3)...os|
|000043d0| 2d 70 6f 70 65 6e 20 20 | 20 20 20 20 20 20 20 20 |-popen | |
|000043e0| 20 20 20 20 20 20 3b 20 | 73 65 65 20 70 6f 70 65 | ; |see pope|
|000043f0| 6e 28 33 29 0a 6f 73 2d | 70 63 6c 6f 73 65 20 20 |n(3).os-|pclose |
|00004400| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 0a 0a 6f | | ..o|
|00004410| 73 2d 67 65 74 65 6e 76 | 0a 6f 73 2d 73 65 74 65 |s-getenv|.os-sete|
|00004420| 6e 76 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |nv | |
|00004430| 20 3b 20 65 6e 76 69 72 | 6f 6e 6d 65 6e 74 20 76 | ; envir|onment v|
|00004440| 61 72 69 61 62 6c 65 73 | 20 61 72 65 0a 6f 73 2d |ariables| are.os-|
|00004450| 75 6e 73 65 74 65 6e 76 | 20 20 20 20 20 20 20 20 |unsetenv| |
|00004460| 20 20 20 20 20 3b 20 70 | 61 73 73 65 64 20 74 6f | ; p|assed to|
|00004470| 20 63 68 69 6c 64 20 70 | 72 6f 63 65 73 73 65 73 | child p|rocesses|
|00004480| 0a 0a 6f 73 2d 67 65 74 | 70 69 64 0a 6f 73 2d 67 |..os-get|pid.os-g|
|00004490| 65 74 70 70 69 64 20 20 | 20 20 20 20 20 20 20 20 |etppid | |
|000044a0| 20 20 20 20 3b 20 67 65 | 74 20 70 72 6f 63 65 73 | ; ge|t proces|
|000044b0| 73 20 69 64 20 6f 66 20 | 70 61 72 65 6e 74 0a 6f |s id of |parent.o|
|000044c0| 73 2d 6b 69 6c 6c 70 67 | 20 20 20 20 20 20 20 20 |s-killpg| |
|000044d0| 20 20 20 20 20 20 20 3b | 20 6b 69 6c 6c 20 61 20 | ;| kill a |
|000044e0| 70 72 6f 63 65 73 73 20 | 67 72 6f 75 70 0a 6f 73 |process |group.os|
|000044f0| 2d 6b 69 6c 6c 70 70 67 | 20 20 20 20 20 20 20 20 |-killppg| |
|00004500| 20 20 20 20 20 20 3b 20 | 6b 69 6c 6c 20 70 61 72 | ; |kill par|
|00004510| 65 6e 74 27 73 20 70 72 | 6f 63 65 73 73 20 67 72 |ent's pr|ocess gr|
|00004520| 6f 75 70 0a 6f 73 2d 6b | 69 6c 6c 61 6c 6c 20 20 |oup.os-k|illall |
|00004530| 20 20 20 20 20 20 20 20 | 20 20 20 20 3b 20 6b 69 | | ; ki|
|00004540| 6c 6c 20 61 6c 6c 20 79 | 6f 75 72 20 70 72 6f 63 |ll all y|our proc|
|00004550| 65 73 73 65 73 20 6f 6e | 20 74 68 69 73 20 6d 61 |esses on| this ma|
|00004560| 63 68 69 6e 65 0a 0a 6f | 73 2d 73 6c 65 65 70 0a |chine..o|s-sleep.|
|00004570| 6f 73 2d 63 75 72 74 69 | 6d 65 20 20 20 20 20 20 |os-curti|me |
|00004580| 20 20 20 20 20 20 20 20 | 3b 20 72 65 74 75 72 6e | |; return|
|00004590| 20 63 75 72 72 65 6e 74 | 20 74 69 6d 65 20 61 73 | current| time as|
|000045a0| 20 69 6e 74 65 67 65 72 | 0a 6f 73 2d 66 69 6c 65 | integer|.os-file|
|000045b0| 6d 6f 64 74 69 6d 65 20 | 20 20 20 20 20 20 20 20 |modtime | |
|000045c0| 20 3b 20 72 65 74 75 72 | 6e 20 66 69 6c 65 20 6d | ; retur|n file m|
|000045d0| 6f 64 69 66 69 63 61 74 | 69 6f 6e 20 74 69 6d 65 |odificat|ion time|
|000045e0| 20 69 6e 74 65 67 65 72 | 0a 6f 73 2d 66 69 6c 65 | integer|.os-file|
|000045f0| 61 63 63 74 69 6d 65 20 | 20 20 20 20 20 20 20 20 |acctime | |
|00004600| 20 3b 20 72 65 74 75 72 | 6e 20 66 69 6c 65 20 61 | ; retur|n file a|
|00004610| 63 63 65 73 73 20 74 69 | 6d 65 20 69 6e 74 65 67 |ccess ti|me integ|
|00004620| 65 72 0a 6f 73 2d 74 69 | 6d 65 73 74 72 69 6e 67 |er.os-ti|mestring|
|00004630| 20 20 20 20 20 20 20 20 | 20 20 20 3b 20 63 6f 6e | | ; con|
|00004640| 76 65 72 74 20 74 69 6d | 65 20 69 6e 74 65 67 65 |vert tim|e intege|
|00004650| 72 20 74 6f 20 68 75 6d | 61 6e 2d 72 65 61 64 61 |r to hum|an-reada|
|00004660| 62 6c 65 20 73 74 72 69 | 6e 67 0a 0a 6f 73 2d 66 |ble stri|ng..os-f|
|00004670| 69 6c 65 73 69 7a 65 20 | 20 20 20 20 20 20 20 20 |ilesize | |
|00004680| 20 20 20 20 3b 20 72 65 | 74 75 72 6e 20 73 69 7a | ; re|turn siz|
|00004690| 65 20 6f 66 20 61 20 66 | 69 6c 65 20 69 6e 20 62 |e of a f|ile in b|
|000046a0| 79 74 65 73 0a 6f 73 2d | 66 69 6c 65 64 69 72 70 |ytes.os-|filedirp|
|000046b0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 3b 20 74 | | ; t|
|000046c0| 72 75 65 20 69 66 20 66 | 69 6c 65 20 69 73 20 61 |rue if f|ile is a|
|000046d0| 20 64 69 72 65 63 74 6f | 72 79 0a 0a 6f 73 2d 68 | directo|ry..os-h|
|000046e0| 6f 73 74 6e 61 6d 65 20 | 20 20 20 20 20 20 20 20 |ostname | |
|000046f0| 20 20 20 20 3b 20 72 65 | 74 75 72 6e 73 20 74 68 | ; re|turns th|
|00004700| 65 20 72 65 73 75 6c 74 | 20 6f 66 20 67 65 74 68 |e result| of geth|
|00004710| 6f 73 74 6e 61 6d 65 28 | 32 29 0a 6f 73 2d 61 72 |ostname(|2).os-ar|
|00004720| 63 68 69 74 65 63 74 75 | 72 65 20 20 20 20 20 20 |chitectu|re |
|00004730| 20 20 20 3b 20 72 65 74 | 75 72 6e 73 20 20 22 6d | ; ret|urns "m|
|00004740| 69 70 73 22 20 6f 72 20 | 22 73 70 61 72 63 22 0a |ips" or |"sparc".|
|00004750| 0a 6f 73 2d 64 65 6c 65 | 74 65 2d 66 69 6c 65 20 |.os-dele|te-file |
|00004760| 20 20 20 20 20 20 20 20 | 20 3b 20 74 68 65 73 65 | | ; these|
|00004770| 20 61 72 65 20 62 75 69 | 6c 74 69 6e 20 2d 20 6c | are bui|ltin - l|
|00004780| 65 73 73 20 6f 76 65 72 | 68 65 61 64 0a 6f 73 2d |ess over|head.os-|
|00004790| 72 65 6e 61 6d 65 2d 66 | 69 6c 65 20 20 20 20 20 |rename-f|ile |
|000047a0| 20 20 20 20 20 3b 20 74 | 68 61 6e 20 73 74 61 72 | ; t|han star|
|000047b0| 74 69 6e 67 20 61 20 73 | 65 70 61 72 61 74 65 20 |ting a s|eparate |
|000047c0| 70 72 6f 63 65 73 73 0a | 6f 73 2d 63 68 6d 6f 64 |process.|os-chmod|
|000047d0| 0a 6f 73 2d 6d 61 6b 65 | 2d 64 69 72 65 63 74 6f |.os-make|-directo|
|000047e0| 72 79 0a 6f 73 2d 67 65 | 74 77 64 0a 6f 73 2d 73 |ry.os-ge|twd.os-s|
|000047f0| 74 61 74 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |tat | |
|00004800| 20 20 20 20 3b 20 73 63 | 6d 2f 66 73 74 72 75 63 | ; sc|m/fstruc|
|00004810| 74 2e 65 20 69 73 20 61 | 6e 20 65 78 61 6d 70 6c |t.e is a|n exampl|
|00004820| 65 20 6f 66 20 63 61 6c | 6c 69 6e 67 0a 20 20 20 |e of cal|ling. |
|00004830| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00004840| 20 20 20 20 20 3b 20 72 | 6f 75 74 69 6e 65 73 20 | ; r|outines |
|00004850| 6c 69 6b 65 20 73 74 61 | 74 28 32 29 20 74 68 61 |like sta|t(2) tha|
|00004860| 74 20 65 78 70 65 63 74 | 20 61 20 73 74 72 75 63 |t expect| a struc|
|00004870| 74 75 72 65 0a 0a 28 6f | 73 2d 70 61 74 68 67 65 |ture..(o|s-pathge|
|00004880| 74 65 78 74 20 22 70 61 | 74 68 22 29 20 20 3b 20 |text "pa|th") ; |
|00004890| 72 65 74 75 72 6e 20 65 | 78 74 65 6e 73 69 6f 6e |return e|xtension|
|000048a0| 3a 20 2f 61 2f 62 2e 63 | 20 2d 3e 20 63 0a 28 6f |: /a/b.c| -> c.(o|
|000048b0| 73 2d 70 61 74 68 64 65 | 6c 65 78 74 20 22 70 61 |s-pathde|lext "pa|
|000048c0| 74 68 22 29 20 20 3b 20 | 64 65 6c 65 74 65 20 65 |th") ; |delete e|
|000048d0| 78 74 65 6e 73 69 6f 6e | 3a 20 2f 61 2f 62 2e 63 |xtension|: /a/b.c|
|000048e0| 20 2d 3e 20 2f 61 2f 62 | 0a 28 6f 73 2d 70 61 74 | -> /a/b|.(os-pat|
|000048f0| 68 67 65 74 70 61 74 68 | 20 22 70 61 74 68 22 29 |hgetpath| "path")|
|00004900| 20 3b 20 72 65 74 75 72 | 6e 20 70 61 74 68 20 70 | ; retur|n path p|
|00004910| 6f 72 74 69 6f 6e 3a 20 | 2f 61 2f 62 2e 63 20 2d |ortion: |/a/b.c -|
|00004920| 3e 20 2f 61 0a 28 6f 73 | 2d 70 61 74 68 67 65 74 |> /a.(os|-pathget|
|00004930| 6e 61 6d 65 20 22 70 61 | 74 68 22 29 20 3b 20 72 |name "pa|th") ; r|
|00004940| 65 74 75 72 6e 20 6e 61 | 6d 65 20 70 6f 72 74 69 |eturn na|me porti|
|00004950| 6f 6e 3a 20 2f 61 2f 62 | 2e 63 20 2d 3e 20 62 2e |on: /a/b|.c -> b.|
|00004960| 63 0a 0a 28 6f 73 2d 75 | 6e 69 71 6e 61 6d 20 22 |c..(os-u|niqnam "|
|00004970| 70 72 65 66 69 78 22 29 | 20 20 20 3b 20 72 65 74 |prefix")| ; ret|
|00004980| 75 72 6e 20 61 20 73 74 | 72 69 6e 67 20 28 74 6f |urn a st|ring (to|
|00004990| 20 62 65 20 75 73 65 64 | 20 61 73 20 61 20 66 69 | be used| as a fi|
|000049a0| 6c 65 6e 61 6d 65 29 0a | 20 20 20 20 20 20 20 20 |lename).| |
|000049b0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|000049c0| 3b 20 74 68 61 74 20 69 | 73 20 75 6e 69 71 75 65 |; that i|s unique|
|000049d0| 20 61 63 72 6f 73 73 20 | 70 72 6f 63 65 73 73 65 | across |processe|
|000049e0| 73 20 61 6e 64 20 68 6f | 73 74 73 0a 20 20 20 20 |s and ho|sts. |
|000049f0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00004a00| 20 20 20 20 0a 28 6f 73 | 2d 67 6c 6f 62 20 22 66 | .(os|-glob "f|
|00004a10| 69 6c 65 2a 22 29 20 20 | 20 20 20 20 20 3b 20 72 |ile*") | ; r|
|00004a20| 65 74 75 72 6e 73 20 61 | 20 6c 69 73 74 20 6f 66 |eturns a| list of|
|00004a30| 20 66 69 6c 65 6e 61 6d | 65 20 73 74 72 69 6e 67 | filenam|e string|
|00004a40| 73 20 6d 61 74 63 68 69 | 6e 67 0a 20 20 20 20 20 |s matchi|ng. |
|00004a50| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00004a60| 20 20 20 3b 20 74 68 65 | 20 66 69 6c 65 20 70 61 | ; the| file pa|
|00004a70| 74 74 65 72 6e 0a 0a 6f | 73 2d 6d 61 6c 6c 6f 63 |ttern..o|s-malloc|
|00004a80| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 3b | | ;|
|00004a90| 20 72 65 74 75 72 6e 73 | 20 74 68 65 20 70 6f 69 | returns| the poi|
|00004aa0| 6e 74 65 72 20 74 6f 20 | 74 68 65 20 61 72 65 61 |nter to |the area|
|00004ab0| 20 2a 61 73 20 61 6e 20 | 69 6e 74 65 67 65 72 2a | *as an |integer*|
|00004ac0| 0a 6f 73 2d 66 72 65 65 | 0a 0a 54 68 65 73 65 20 |.os-free|..These |
|00004ad0| 66 75 6e 63 74 69 6f 6e | 73 20 66 72 6f 6d 20 74 |function|s from t|
|00004ae0| 68 65 20 45 6c 6b 20 6c | 69 62 72 61 72 79 20 61 |he Elk l|ibrary a|
|00004af0| 72 65 20 67 69 76 65 6e | 20 61 6c 74 65 72 6e 61 |re given| alterna|
|00004b00| 74 65 20 6e 61 6d 65 73 | 20 75 73 69 6e 67 0a 74 |te names| using.t|
|00004b10| 68 65 20 6f 73 2d 20 63 | 6f 6e 76 65 6e 74 69 6f |he os- c|onventio|
|00004b20| 6e 20 28 69 2e 65 2e 2c | 20 73 74 61 6e 64 61 72 |n (i.e.,| standar|
|00004b30| 64 20 45 6c 6b 20 63 6f | 6e 74 61 69 6e 73 20 61 |d Elk co|ntains a|
|00004b40| 20 66 75 6e 63 74 69 6f | 6e 20 72 65 61 64 2d 64 | functio|n read-d|
|00004b50| 69 72 65 63 74 6f 72 79 | 29 3a 0a 0a 6f 73 2d 72 |irectory|):..os-r|
|00004b60| 65 61 64 2d 64 69 72 65 | 63 74 6f 72 79 20 20 20 |ead-dire|ctory |
|00004b70| 20 20 20 20 3b 20 72 65 | 74 75 72 6e 73 20 61 20 | ; re|turns a |
|00004b80| 6c 69 73 74 20 6f 66 20 | 66 69 6c 65 73 20 69 6e |list of |files in|
|00004b90| 20 61 20 64 69 72 65 63 | 74 6f 72 79 0a 6f 73 2d | a direc|tory.os-|
|00004ba0| 66 69 6c 65 2d 73 74 61 | 74 75 73 20 20 20 20 20 |file-sta|tus |
|00004bb0| 20 20 20 20 20 3b 20 72 | 65 74 75 72 6e 73 20 27 | ; r|eturns '|
|00004bc0| 64 69 72 65 63 74 6f 72 | 79 20 6f 72 20 27 72 65 |director|y or 're|
|00004bd0| 67 75 6c 61 72 0a 6f 73 | 2d 66 69 6c 65 2d 65 78 |gular.os|-file-ex|
|00004be0| 69 73 74 73 3f 0a 0a 5c | 65 6e 64 7b 76 65 72 62 |ists?..\|end{verb|
|00004bf0| 61 74 69 6d 7d 0a 0a 0a | 0a 5c 73 65 63 74 69 6f |atim}...|.\sectio|
|00004c00| 6e 7b 50 72 6f 67 72 61 | 6d 6d 69 6e 67 20 77 69 |n{Progra|mming wi|
|00004c10| 74 68 20 74 68 65 20 46 | 6f 72 65 69 67 6e 20 46 |th the F|oreign F|
|00004c20| 75 6e 63 74 69 6f 6e 20 | 49 6e 74 65 72 66 61 63 |unction |Interfac|
|00004c30| 65 7d 0a 0a 54 68 65 20 | 45 6c 6b 20 69 6d 70 6c |e}..The |Elk impl|
|00004c40| 65 6d 65 6e 74 61 74 69 | 6f 6e 20 6f 66 20 53 63 |ementati|on of Sc|
|00004c50| 68 65 6d 65 20 69 73 20 | 64 65 73 69 67 6e 65 64 |heme is |designed|
|00004c60| 20 74 6f 20 61 6c 6c 6f | 77 20 70 72 6f 67 72 61 | to allo|w progra|
|00004c70| 6d 73 20 74 6f 20 62 65 | 0a 77 72 69 74 74 65 6e |ms to be|.written|
|00004c80| 20 69 6e 20 6d 69 78 74 | 75 72 65 73 20 6f 66 20 | in mixt|ures of |
|00004c90| 53 63 68 65 6d 65 20 61 | 6e 64 20 43 2c 20 61 73 |Scheme a|nd C, as|
|00004ca0| 20 61 70 70 72 6f 70 72 | 69 61 74 65 2e 20 20 49 | appropr|iate. I|
|00004cb0| 74 20 70 72 6f 76 69 64 | 65 73 0a 6c 69 6e 6b 69 |t provid|es.linki|
|00004cc0| 6e 67 20 6f 66 20 63 6f | 6d 70 69 6c 65 64 20 43 |ng of co|mpiled C|
|00004cd0| 20 6f 62 6a 65 63 74 20 | 66 69 6c 65 73 20 61 74 | object |files at|
|00004ce0| 20 72 75 6e 2d 74 69 6d | 65 20 28 64 79 6e 61 6d | run-tim|e (dynam|
|00004cf0| 69 63 20 6c 69 6e 6b 69 | 6e 67 29 2c 0a 61 6e 64 |ic linki|ng),.and|
|00004d00| 20 43 20 63 6f 64 65 20 | 63 61 6e 20 65 78 70 6f | C code |can expo|
|00004d10| 72 74 20 6e 65 77 20 64 | 61 74 61 20 74 79 70 65 |rt new d|ata type|
|00004d20| 73 20 74 6f 20 53 63 68 | 65 6d 65 2e 20 20 49 6e |s to Sch|eme. In|
|00004d30| 74 65 72 66 61 63 69 6e | 67 20 43 20 74 6f 20 45 |terfacin|g C to E|
|00004d40| 6c 6b 0a 69 73 20 64 65 | 73 63 72 69 62 65 64 20 |lk.is de|scribed |
|00004d50| 69 6e 20 74 68 65 20 66 | 69 6c 65 20 65 78 2e 6d |in the f|ile ex.m|
|00004d60| 73 20 69 6e 20 74 68 65 | 20 45 6c 6b 20 64 6f 63 |s in the| Elk doc|
|00004d70| 2f 20 64 69 72 65 63 74 | 6f 72 79 2e 0a 0a 49 6e |/ direct|ory...In|
|00004d80| 20 73 74 61 6e 64 61 72 | 64 20 45 6c 6b 2c 20 65 | standar|d Elk, e|
|00004d90| 61 63 68 20 43 20 72 6f | 75 74 69 6e 65 20 77 68 |ach C ro|utine wh|
|00004da0| 69 63 68 20 77 69 6c 6c | 20 62 65 20 63 61 6c 6c |ich will| be call|
|00004db0| 61 62 6c 65 20 66 72 6f | 6d 20 53 63 68 65 6d 65 |able fro|m Scheme|
|00004dc0| 0a 6d 75 73 74 20 62 65 | 20 69 6e 74 65 72 66 61 |.must be| interfa|
|00004dd0| 63 65 64 20 74 6f 20 53 | 63 68 65 6d 65 20 77 69 |ced to S|cheme wi|
|00004de0| 74 68 20 61 20 73 68 6f | 72 74 20 77 72 61 70 70 |th a sho|rt wrapp|
|00004df0| 65 72 20 6f 72 20 67 6c | 75 65 20 66 75 6e 63 74 |er or gl|ue funct|
|00004e00| 69 6f 6e 2e 0a 54 68 69 | 73 20 66 75 6e 63 74 69 |ion..Thi|s functi|
|00004e10| 6f 6e 20 69 73 20 74 79 | 70 69 63 61 6c 6c 79 20 |on is ty|pically |
|00004e20| 35 2d 31 30 20 6c 69 6e | 65 73 20 6c 6f 6e 67 20 |5-10 lin|es long |
|00004e30| 61 6e 64 20 69 73 20 65 | 61 73 79 20 74 6f 20 77 |and is e|asy to w|
|00004e40| 72 69 74 65 2e 0a 49 66 | 20 6f 6e 65 20 69 73 20 |rite..If| one is |
|00004e50| 74 72 79 69 6e 67 20 74 | 6f 20 69 6e 74 65 72 66 |trying t|o interf|
|00004e60| 61 63 65 20 74 6f 20 61 | 20 6c 61 72 67 65 20 6c |ace to a| large l|
|00004e70| 69 62 72 61 72 79 20 73 | 75 63 68 20 61 73 20 58 |ibrary s|uch as X|
|00004e80| 20 77 69 6e 64 6f 77 73 | 20 6f 72 20 53 47 49 27 | windows| or SGI'|
|00004e90| 73 20 47 4c 0a 6c 69 62 | 72 61 72 79 2c 20 74 68 |s GL.lib|rary, th|
|00004ea0| 65 20 67 6c 75 65 20 66 | 75 6e 63 74 69 6f 6e 73 |e glue f|unctions|
|00004eb0| 20 72 65 70 72 65 73 65 | 6e 74 20 73 6f 6d 65 20 | represe|nt some |
|00004ec0| 61 6d 6f 75 6e 74 20 6f | 66 20 77 6f 72 6b 20 73 |amount o|f work s|
|00004ed0| 69 6d 70 6c 79 20 64 75 | 65 20 74 6f 20 74 68 65 |imply du|e to the|
|00004ee0| 0a 6c 61 72 67 65 20 6e | 75 6d 62 65 72 20 6f 66 |.large n|umber of|
|00004ef0| 20 65 6e 74 72 69 65 73 | 2e 0a 0a 54 68 65 20 66 | entries|...The f|
|00004f00| 6f 72 65 69 67 6e 20 66 | 75 6e 63 74 69 6f 6e 20 |oreign f|unction |
|00004f10| 69 6e 74 65 72 66 61 63 | 65 20 61 6c 6c 6f 77 73 |interfac|e allows|
|00004f20| 20 7b 5c 65 6d 20 73 6f | 6d 65 7d 20 43 20 66 75 | {\em so|me} C fu|
|00004f30| 6e 63 74 69 6f 6e 73 20 | 74 6f 20 62 65 20 69 6e |nctions |to be in|
|00004f40| 74 65 72 66 61 63 65 64 | 0a 69 6e 20 61 20 73 69 |terfaced|.in a si|
|00004f50| 6e 67 6c 65 20 63 61 6c | 6c 20 6f 72 20 74 61 62 |ngle cal|l or tab|
|00004f60| 6c 65 20 65 6e 74 72 79 | 2c 20 65 6c 69 6d 69 6e |le entry|, elimin|
|00004f70| 61 74 69 6e 67 20 74 68 | 65 20 6e 65 65 64 20 74 |ating th|e need t|
|00004f80| 6f 20 77 72 69 74 65 20 | 61 20 67 6c 75 65 0a 66 |o write |a glue.f|
|00004f90| 75 6e 63 74 69 6f 6e 2e | 20 20 46 6f 72 20 65 78 |unction.| For ex|
|00004fa0| 61 6d 70 6c 65 2c 20 67 | 65 74 65 6e 76 20 63 61 |ample, g|etenv ca|
|00004fb0| 6e 20 62 65 20 65 78 70 | 6f 72 74 65 64 20 74 6f |n be exp|orted to|
|00004fc0| 20 53 63 68 65 6d 65 20 | 77 69 74 68 20 74 68 65 | Scheme |with the|
|00004fd0| 20 63 61 6c 6c 3a 0a 5c | 62 65 67 69 6e 7b 76 65 | call:.\|begin{ve|
|00004fe0| 72 62 61 74 69 6d 7d 0a | 20 20 20 20 44 65 66 69 |rbatim}.| Defi|
|00004ff0| 6e 65 5f 46 6f 72 65 69 | 67 6e 28 22 67 65 74 65 |ne_Forei|gn("gete|
|00005000| 6e 76 22 2c 67 65 74 65 | 6e 76 2c 22 53 52 53 22 |nv",gete|nv,"SRS"|
|00005010| 29 3b 0a 5c 65 6e 64 7b | 76 65 72 62 61 74 69 6d |);.\end{|verbatim|
|00005020| 7d 0a 72 61 74 68 65 72 | 20 74 68 61 6e 20 75 73 |}.rather| than us|
|00005030| 69 6e 67 20 61 20 67 6c | 75 65 20 72 6f 75 74 69 |ing a gl|ue routi|
|00005040| 6e 65 20 6c 69 6b 65 0a | 5c 62 65 67 69 6e 7b 76 |ne like.|\begin{v|
|00005050| 65 72 62 61 74 69 6d 7d | 0a 20 20 20 20 73 74 61 |erbatim}|. sta|
|00005060| 74 69 63 20 4f 62 6a 65 | 63 74 20 50 5f 47 65 74 |tic Obje|ct P_Get|
|00005070| 65 6e 76 20 28 65 29 20 | 4f 62 6a 65 63 74 20 65 |env (e) |Object e|
|00005080| 3b 20 7b 0a 20 20 20 20 | 20 20 20 20 72 65 67 69 |; {. | regi|
|00005090| 73 74 65 72 20 63 68 61 | 72 20 2a 73 3b 0a 20 20 |ster cha|r *s;. |
|000050a0| 20 20 20 20 20 20 4f 62 | 6a 65 63 74 20 72 65 74 | Ob|ject ret|
|000050b0| 3b 0a 20 20 20 20 20 20 | 20 20 44 65 63 6c 61 72 |;. | Declar|
|000050c0| 65 5f 43 5f 53 74 72 69 | 6e 67 73 3b 0a 0a 20 20 |e_C_Stri|ngs;.. |
|000050d0| 20 20 20 20 20 20 4d 61 | 6b 65 5f 43 5f 53 74 72 | Ma|ke_C_Str|
|000050e0| 69 6e 67 20 28 65 2c 20 | 73 29 3b 0a 20 20 20 20 |ing (e, |s);. |
|000050f0| 20 20 20 20 72 65 74 20 | 3d 20 28 73 20 3d 20 67 | ret |= (s = g|
|00005100| 65 74 65 6e 76 20 28 73 | 29 29 20 3f 20 4d 61 6b |etenv (s|)) ? Mak|
|00005110| 65 5f 53 74 72 69 6e 67 | 20 28 73 2c 20 73 74 72 |e_String| (s, str|
|00005120| 6c 65 6e 20 28 73 29 29 | 20 3a 20 46 61 6c 73 65 |len (s))| : False|
|00005130| 3b 0a 20 20 20 20 20 20 | 20 20 44 69 73 70 6f 73 |;. | Dispos|
|00005140| 65 5f 43 5f 53 74 72 69 | 6e 67 73 3b 0a 20 20 20 |e_C_Stri|ngs;. |
|00005150| 20 20 20 20 20 72 65 74 | 75 72 6e 20 72 65 74 3b | ret|urn ret;|
|00005160| 0a 20 20 20 20 7d 20 2f | 2a 67 65 74 65 6e 76 2a |. } /|*getenv*|
|00005170| 2f 0a 5c 65 6e 64 7b 76 | 65 72 62 61 74 69 6d 7d |/.\end{v|erbatim}|
|00005180| 0a 0a 49 74 20 69 73 20 | 70 6f 73 73 69 62 6c 65 |..It is |possible|
|00005190| 20 74 6f 20 77 72 69 74 | 65 20 43 20 6c 69 62 72 | to writ|e C libr|
|000051a0| 61 72 69 65 73 20 74 68 | 61 74 20 63 61 6e 20 62 |aries th|at can b|
|000051b0| 65 20 63 61 6c 6c 65 64 | 20 66 72 6f 6d 20 53 63 |e called| from Sc|
|000051c0| 68 65 6d 65 0a 61 6e 64 | 20 74 68 61 74 20 63 61 |heme.and| that ca|
|000051d0| 6e 20 61 6c 73 6f 20 62 | 65 20 75 73 65 64 20 61 |n also b|e used a|
|000051e0| 73 20 6e 6f 72 6d 61 6c | 20 43 20 6c 69 62 72 61 |s normal| C libra|
|000051f0| 72 69 65 73 3b 20 0a 73 | 65 65 20 74 68 65 20 73 |ries; .s|ee the s|
|00005200| 65 63 74 69 6f 6e 20 22 | 46 6f 72 65 69 67 6e 20 |ection "|Foreign |
|00005210| 4c 69 62 72 61 72 69 65 | 73 22 2e 0a 0a 41 66 74 |Librarie|s"...Aft|
|00005220| 65 72 20 61 20 66 75 6e | 63 74 69 6f 6e 20 69 73 |er a fun|ction is|
|00005230| 20 64 65 66 69 6e 65 64 | 0a 69 74 20 63 61 6e 20 | defined|.it can |
|00005240| 62 65 20 63 61 6c 6c 65 | 64 20 6e 6f 72 6d 61 6c |be calle|d normal|
|00005250| 6c 79 20 66 72 6f 6d 20 | 53 63 68 65 6d 65 2c 20 |ly from |Scheme, |
|00005260| 66 6f 72 20 65 78 61 6d | 70 6c 65 2c 0a 5c 62 65 |for exam|ple,.\be|
|00005270| 67 69 6e 7b 76 65 72 62 | 61 74 69 6d 7d 0a 20 20 |gin{verb|atim}. |
|00005280| 20 20 28 67 65 74 65 6e | 76 20 22 54 45 52 4d 22 | (geten|v "TERM"|
|00005290| 29 20 3d 3e 20 22 78 74 | 65 72 6d 22 0a 5c 65 6e |) => "xt|erm".\en|
|000052a0| 64 7b 76 65 72 62 61 74 | 69 6d 7d 0a 0a 54 68 65 |d{verbat|im}..The|
|000052b0| 20 61 72 67 75 6d 65 6e | 74 73 20 74 6f 20 44 65 | argumen|ts to De|
|000052c0| 66 69 6e 65 5c 5f 46 6f | 72 65 69 67 6e 20 61 72 |fine\_Fo|reign ar|
|000052d0| 65 20 74 68 65 20 6e 61 | 6d 65 20 6f 66 20 74 68 |e the na|me of th|
|000052e0| 65 20 66 75 6e 63 74 69 | 6f 6e 20 69 6e 20 53 63 |e functi|on in Sc|
|000052f0| 68 65 6d 65 20 0a 28 77 | 68 69 63 68 20 6d 69 67 |heme .(w|hich mig|
|00005300| 68 74 20 62 65 20 63 68 | 6f 73 65 6e 20 74 6f 20 |ht be ch|osen to |
|00005310| 63 6f 6e 66 6f 72 6d 20 | 6d 6f 72 65 20 74 6f 20 |conform |more to |
|00005320| 73 63 68 65 6d 65 2d 6c | 69 6b 65 20 6e 61 6d 69 |scheme-l|ike nami|
|00005330| 6e 67 20 63 6f 6e 76 65 | 6e 74 69 6f 6e 73 2c 20 |ng conve|ntions, |
|00005340| 65 2e 67 2e 2c 0a 60 73 | 74 72 69 6e 67 2d 6c 65 |e.g.,.`s|tring-le|
|00005350| 6e 67 74 68 27 20 72 61 | 74 68 65 72 20 74 68 61 |ngth' ra|ther tha|
|00005360| 6e 20 60 73 74 72 6c 65 | 6e 27 29 2c 20 74 68 65 |n `strle|n'), the|
|00005370| 20 43 20 65 6e 74 72 79 | 20 70 6f 69 6e 74 2c 20 | C entry| point, |
|00005380| 0a 61 6e 64 20 61 6e 20 | 61 72 67 75 6d 65 6e 74 |.and an |argument|
|00005390| 20 64 65 73 63 72 69 70 | 74 69 6f 6e 20 73 74 72 | descrip|tion str|
|000053a0| 69 6e 67 2e 20 0a 54 68 | 65 20 61 72 67 75 6d 65 |ing. .Th|e argume|
|000053b0| 6e 74 20 64 65 73 63 72 | 69 70 74 69 6f 6e 20 73 |nt descr|iption s|
|000053c0| 74 72 69 6e 67 20 60 60 | 53 52 53 27 27 20 69 6e |tring ``|SRS'' in|
|000053d0| 20 74 68 69 73 20 65 78 | 61 6d 70 6c 65 20 6d 65 | this ex|ample me|
|000053e0| 61 6e 73 20 0a 53 74 72 | 69 6e 67 2c 52 65 74 75 |ans .Str|ing,Retu|
|000053f0| 72 6e 73 20 53 74 72 69 | 6e 67 2e 20 20 41 72 67 |rns Stri|ng. Arg|
|00005400| 75 6d 65 6e 74 20 64 65 | 73 63 72 69 70 74 69 6f |ument de|scriptio|
|00005410| 6e 20 73 74 72 69 6e 67 | 73 20 63 6f 6e 73 69 73 |n string|s consis|
|00005420| 74 20 6f 66 3a 0a 5c 62 | 65 67 69 6e 7b 76 65 72 |t of:.\b|egin{ver|
|00005430| 62 61 74 69 6d 7d 0a 20 | 20 20 20 20 20 20 20 42 |batim}. | B|
|00005440| 20 20 20 20 20 20 20 53 | 63 68 65 6d 65 20 62 6f | S|cheme bo|
|00005450| 6f 6c 65 61 6e 20 3c 2d | 3e 20 43 20 69 6e 74 20 |olean <-|> C int |
|00005460| 30 20 6f 72 20 31 0a 20 | 20 20 20 20 20 20 20 49 |0 or 1. | I|
|00005470| 20 20 20 20 20 20 20 69 | 6e 74 65 67 65 72 0a 20 | i|nteger. |
|00005480| 20 20 20 20 20 20 20 46 | 20 20 20 20 20 20 20 64 | F| d|
|00005490| 6f 75 62 6c 65 20 28 6f | 72 20 66 6c 6f 61 74 3b |ouble (o|r float;|
|000054a0| 20 73 65 65 20 62 65 6c | 6f 77 29 0a 20 20 20 20 | see bel|ow). |
|000054b0| 20 20 20 20 66 20 20 20 | 20 20 20 20 66 6c 6f 61 | f | floa|
|000054c0| 74 0a 20 20 20 20 20 20 | 20 20 53 20 20 20 20 20 |t. | S |
|000054d0| 20 20 73 74 72 69 6e 67 | 20 28 63 68 61 72 20 2a | string| (char *|
|000054e0| 29 0a 20 20 20 20 20 20 | 20 20 50 20 20 20 20 20 |). | P |
|000054f0| 20 20 70 6f 72 74 20 28 | 46 49 4c 45 20 2a 29 0a | port (|FILE *).|
|00005500| 20 20 20 20 20 20 20 20 | 41 20 20 20 20 20 20 20 | |A |
|00005510| 66 6f 72 65 69 67 6e 20 | 61 72 72 61 79 20 28 73 |foreign |array (s|
|00005520| 65 65 20 62 65 6c 6f 77 | 29 0a 5c 65 6e 64 7b 76 |ee below|).\end{v|
|00005530| 65 72 62 61 74 69 6d 7d | 0a 54 68 65 20 6c 69 62 |erbatim}|.The lib|
|00005540| 6d 20 65 6e 74 72 79 20 | 70 6f 77 28 29 20 77 6f |m entry |pow() wo|
|00005550| 75 6c 64 20 62 65 20 64 | 65 63 6c 61 72 65 64 2c |uld be d|eclared,|
|00005560| 0a 5c 62 65 67 69 6e 7b | 76 65 72 62 61 74 69 6d |.\begin{|verbatim|
|00005570| 7d 0a 20 20 20 20 44 65 | 66 69 6e 65 5f 46 6f 72 |}. De|fine_For|
|00005580| 65 69 67 6e 28 22 70 6f | 77 22 2c 70 6f 77 2c 22 |eign("po|w",pow,"|
|00005590| 46 46 52 46 22 29 3b 0a | 5c 65 6e 64 7b 76 65 72 |FFRF");.|\end{ver|
|000055a0| 62 61 74 69 6d 7d 0a 69 | 2e 65 2e 20 70 6f 77 28 |batim}.i|.e. pow(|
|000055b0| 29 20 74 61 6b 65 73 20 | 74 77 6f 20 64 6f 75 62 |) takes |two doub|
|000055c0| 6c 65 73 20 61 6e 64 20 | 72 65 74 75 72 6e 73 20 |les and |returns |
|000055d0| 61 20 64 6f 75 62 6c 65 | 2e 0a 0a 0a 53 63 68 65 |a double|....Sche|
|000055e0| 6d 65 20 7b 5c 65 6d 20 | 70 6f 72 74 73 7d 20 61 |me {\em |ports} a|
|000055f0| 72 65 20 70 61 73 73 65 | 64 20 74 6f 20 43 20 66 |re passe|d to C f|
|00005600| 75 6e 63 74 69 6f 6e 73 | 20 61 73 20 5c 76 65 72 |unctions| as \ver|
|00005610| 62 7c 46 49 4c 45 20 2a | 7c 20 76 61 72 69 61 62 |b|FILE *|| variab|
|00005620| 6c 65 73 2e 0a 53 63 68 | 65 6d 65 20 42 6f 6f 6c |les..Sch|eme Bool|
|00005630| 65 61 6e 73 20 61 72 65 | 20 70 61 73 73 65 64 20 |eans are| passed |
|00005640| 74 6f 20 43 20 61 73 20 | 74 68 65 20 69 6e 74 65 |to C as |the inte|
|00005650| 67 65 72 73 20 7a 65 72 | 6f 20 6f 72 20 6f 6e 65 |gers zer|o or one|
|00005660| 2e 0a 46 75 6e 63 74 69 | 6f 6e 73 20 77 68 69 63 |..Functi|ons whic|
|00005670| 68 20 72 65 74 75 72 6e | 20 5c 76 65 72 62 7c 63 |h return| \verb|c|
|00005680| 68 61 72 20 2a 7c 20 72 | 65 73 75 6c 74 20 69 6e |har *| r|esult in|
|00005690| 20 74 68 65 20 63 72 65 | 61 74 69 6f 6e 20 6f 66 | the cre|ation of|
|000056a0| 20 61 20 53 63 68 65 6d | 65 0a 73 74 72 69 6e 67 | a Schem|e.string|
|000056b0| 20 28 61 6c 6c 6f 63 61 | 74 65 64 20 6f 6e 20 74 | (alloca|ted on t|
|000056c0| 68 65 20 53 63 68 65 6d | 65 20 68 65 61 70 29 2e |he Schem|e heap).|
|000056d0| 20 20 54 68 69 73 20 77 | 6f 72 6b 73 20 63 6f 72 | This w|orks cor|
|000056e0| 72 65 63 74 6c 79 20 66 | 6f 72 0a 43 20 66 75 6e |rectly f|or.C fun|
|000056f0| 63 74 69 6f 6e 73 20 73 | 75 63 68 20 61 73 20 5c |ctions s|uch as \|
|00005700| 76 65 72 62 7c 67 65 74 | 65 6e 76 7c 20 77 68 69 |verb|get|env| whi|
|00005710| 63 68 20 72 65 74 75 72 | 6e 20 61 20 70 6f 69 6e |ch retur|n a poin|
|00005720| 74 65 72 20 74 6f 20 61 | 20 73 74 61 74 69 63 61 |ter to a| statica|
|00005730| 6c 6c 79 0a 61 6c 6c 6f | 63 61 74 65 64 20 73 74 |lly.allo|cated st|
|00005740| 72 69 6e 67 2e 0a 52 6f | 75 74 69 6e 65 73 20 77 |ring..Ro|utines w|
|00005750| 68 69 63 68 20 72 65 74 | 75 72 6e 20 61 20 70 6f |hich ret|urn a po|
|00005760| 69 6e 74 65 72 20 74 6f | 20 61 20 73 74 72 69 6e |inter to| a strin|
|00005770| 67 20 61 6c 6c 6f 63 61 | 74 65 64 20 77 69 74 68 |g alloca|ted with|
|00005780| 20 5c 76 65 72 62 7c 6d | 61 6c 6c 6f 63 7c 0a 72 | \verb|m|alloc|.r|
|00005790| 65 73 75 6c 74 20 69 6e | 20 61 20 6d 65 6d 6f 72 |esult in| a memor|
|000057a0| 79 20 6c 65 61 6b 20 68 | 6f 77 65 76 65 72 0a 28 |y leak h|owever.(|
|000057b0| 74 68 65 20 61 6c 6c 6f | 63 61 74 65 64 20 73 74 |the allo|cated st|
|000057c0| 72 69 6e 67 20 69 73 20 | 63 6f 70 69 65 64 20 61 |ring is |copied a|
|000057d0| 6e 64 20 61 67 61 69 6e | 20 61 6c 6c 6f 63 61 74 |nd again| allocat|
|000057e0| 65 64 29 3b 0a 73 75 63 | 68 20 66 75 6e 63 74 69 |ed);.suc|h functi|
|000057f0| 6f 6e 73 20 6e 65 65 64 | 20 61 20 77 72 61 70 70 |ons need| a wrapp|
|00005800| 65 72 20 66 75 6e 63 74 | 69 6f 6e 20 69 66 20 74 |er funct|ion if t|
|00005810| 68 65 20 6d 65 6d 6f 72 | 79 20 6c 65 61 6b 20 69 |he memor|y leak i|
|00005820| 73 20 74 6f 20 62 65 20 | 70 72 65 76 65 6e 74 65 |s to be |prevente|
|00005830| 64 2e 0a 0a 5c 73 75 62 | 73 65 63 74 69 6f 6e 7b |d...\sub|section{|
|00005840| 46 75 6e 63 74 69 6f 6e | 20 54 61 62 6c 65 73 7d |Function| Tables}|
|00005850| 0a 0a 41 20 6e 75 6d 62 | 65 72 20 6f 66 20 66 75 |..A numb|er of fu|
|00005860| 6e 63 74 69 6f 6e 73 20 | 63 61 6e 20 62 65 20 64 |nctions |can be d|
|00005870| 65 63 6c 61 72 65 64 20 | 61 74 20 6f 6e 63 65 20 |eclared |at once |
|00005880| 75 73 69 6e 67 20 61 20 | 66 6f 72 65 69 67 6e 20 |using a |foreign |
|00005890| 66 75 6e 63 74 69 6f 6e | 0a 74 61 62 6c 65 2e 0a |function|.table..|
|000058a0| 5c 62 65 67 69 6e 7b 76 | 65 72 62 61 74 69 6d 7d |\begin{v|erbatim}|
|000058b0| 0a 20 20 20 20 20 20 20 | 20 23 69 6e 63 6c 75 64 |. | #includ|
|000058c0| 65 20 3c 7a 65 6c 6b 2e | 68 3e 0a 20 20 0a 20 20 |e <zelk.|h>. . |
|000058d0| 20 20 20 20 20 20 73 74 | 61 74 69 63 20 73 74 72 | st|atic str|
|000058e0| 75 63 74 20 66 6f 72 64 | 65 66 20 66 6f 72 74 61 |uct ford|ef forta|
|000058f0| 62 5b 5d 20 3d 20 7b 0a | 20 20 20 20 20 20 20 20 |b[] = {.| |
|00005900| 20 20 20 20 20 20 20 20 | 7b 20 22 70 6f 77 22 2c | |{ "pow",|
|00005910| 20 70 6f 77 2c 20 22 46 | 46 52 46 22 20 7d 2c 0a | pow, "F|FRF" },.|
|00005920| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00005930| 7b 20 22 67 65 74 65 6e | 76 22 2c 20 67 65 74 65 |{ "geten|v", gete|
|00005940| 6e 76 2c 20 22 22 20 7d | 2c 0a 20 20 20 20 20 20 |nv, "" }|,. |
|00005950| 20 20 20 20 20 20 20 20 | 20 20 2f 2a 20 65 74 63 | | /* etc|
|00005960| 20 2a 2f 2c 0a 0a 20 20 | 20 20 20 20 20 20 20 20 | */,.. | |
|00005970| 20 20 20 20 20 20 2f 2a | 20 65 6e 64 20 74 68 65 | /*| end the|
|00005980| 20 74 61 62 6c 65 20 77 | 69 74 68 20 74 68 69 73 | table w|ith this|
|00005990| 20 2a 2f 0a 20 20 20 20 | 20 20 20 20 20 20 20 20 | */. | |
|000059a0| 20 20 20 20 7b 20 28 63 | 68 61 72 20 2a 29 30 2c | { (c|har *)0,|
|000059b0| 20 30 2c 20 28 63 68 61 | 72 20 2a 29 30 20 7d 0a | 0, (cha|r *)0 }.|
|000059c0| 20 20 20 20 20 20 20 20 | 7d 3b 0a 20 20 20 20 20 | |};. |
|000059d0| 20 20 20 2e 2e 2e 2e 0a | 0a 20 20 20 20 20 20 20 | .....|. |
|000059e0| 20 44 65 66 69 6e 65 5f | 46 6f 72 74 61 62 28 66 | Define_|Fortab(f|
|000059f0| 6f 72 74 61 62 29 3b 0a | 20 20 20 20 20 20 20 20 |ortab);.| |
|00005a00| 2e 2e 2e 0a 5c 65 6e 64 | 7b 76 65 72 62 61 74 69 |....\end|{verbati|
|00005a10| 6d 7d 0a 0a 0a 0a 5c 73 | 75 62 73 65 63 74 69 6f |m}....\s|ubsectio|
|00005a20| 6e 7b 46 6f 72 65 69 67 | 6e 20 4c 69 62 72 61 72 |n{Foreig|n Librar|
|00005a30| 69 65 73 7d 0a 0a 54 68 | 65 72 65 20 61 72 65 20 |ies}..Th|ere are |
|00005a40| 73 65 76 65 72 61 6c 20 | 77 61 79 73 20 6f 66 20 |several |ways of |
|00005a50| 69 6e 69 74 69 61 74 69 | 6e 67 20 74 68 65 20 64 |initiati|ng the d|
|00005a60| 65 66 69 6e 69 74 69 6f | 6e 20 6f 66 20 66 6f 72 |efinitio|n of for|
|00005a70| 65 69 67 6e 20 66 75 6e | 63 74 69 6f 6e 73 2e 0a |eign fun|ctions..|
|00005a80| 0a 41 20 66 69 6c 65 20 | 63 6f 6e 74 61 69 6e 69 |.A file |containi|
|00005a90| 6e 67 20 66 6f 72 65 69 | 67 6e 20 66 75 6e 63 74 |ng forei|gn funct|
|00005aa0| 69 6f 6e 73 20 63 61 6e | 20 62 65 20 73 74 61 74 |ions can| be stat|
|00005ab0| 69 63 61 6c 6c 79 20 6c | 69 6e 6b 65 64 20 69 6e |ically l|inked in|
|00005ac0| 74 6f 20 0a 74 68 65 20 | 45 6c 6b 20 6b 65 72 6e |to .the |Elk kern|
|00005ad0| 65 6c 2e 0a 49 6e 20 74 | 68 69 73 20 63 61 73 65 |el..In t|his case|
|00005ae0| 20 69 74 20 73 68 6f 75 | 6c 64 20 68 61 76 65 20 | it shou|ld have |
|00005af0| 61 6e 20 69 6e 69 74 69 | 61 6c 69 7a 61 74 69 6f |an initi|alizatio|
|00005b00| 6e 20 72 6f 75 74 69 6e | 65 20 77 68 69 63 68 20 |n routin|e which |
|00005b10| 63 61 6c 6c 73 0a 20 20 | 7b 5c 74 74 20 20 44 65 |calls. |{\tt De|
|00005b20| 66 69 6e 65 5c 5f 46 6f | 72 65 69 67 6e 28 29 20 |fine\_Fo|reign() |
|00005b30| 7d 20 6f 72 20 7b 5c 74 | 74 20 44 65 66 69 6e 65 |} or {\t|t Define|
|00005b40| 5c 5f 46 6f 72 74 61 62 | 28 29 20 7d 0a 74 6f 20 |\_Fortab|() }.to |
|00005b50| 65 78 70 6f 72 74 20 74 | 68 65 20 66 6f 72 65 69 |export t|he forei|
|00005b60| 67 6e 20 66 75 6e 63 74 | 69 6f 6e 73 20 74 6f 20 |gn funct|ions to |
|00005b70| 65 6c 6b 2e 0a 54 68 69 | 73 20 69 6e 69 74 69 61 |elk..Thi|s initia|
|00005b80| 6c 69 7a 61 74 69 6f 6e | 20 72 6f 75 74 69 6e 65 |lization| routine|
|00005b90| 20 73 68 6f 75 6c 64 20 | 62 65 20 63 61 6c 6c 65 | should |be calle|
|00005ba0| 64 20 66 72 6f 6d 20 0a | 5c 62 65 67 69 6e 7b 76 |d from .|\begin{v|
|00005bb0| 65 72 62 61 74 69 6d 7d | 0a 20 20 20 20 49 6e 69 |erbatim}|. Ini|
|00005bc0| 74 5f 45 76 65 72 79 74 | 68 69 6e 67 28 29 0a 5c |t_Everyt|hing().\|
|00005bd0| 65 6e 64 7b 76 65 72 62 | 61 74 69 6d 7d 0a 69 6e |end{verb|atim}.in|
|00005be0| 20 6d 61 69 6e 2e 63 3b | 20 65 64 69 74 20 6d 61 | main.c;| edit ma|
|00005bf0| 69 6e 2e 63 20 74 6f 20 | 64 6f 20 74 68 69 73 2e |in.c to |do this.|
|00005c00| 0a 0a 41 6c 74 65 72 6e | 61 74 69 76 65 6c 79 2c |..Altern|atively,|
|00005c10| 20 74 68 65 20 66 6f 72 | 65 69 67 6e 20 63 6f 64 | the for|eign cod|
|00005c20| 65 20 63 61 6e 20 62 65 | 20 6b 65 70 74 20 69 6e |e can be| kept in|
|00005c30| 20 61 20 73 65 70 61 72 | 61 74 65 20 2e 6f 20 66 | a separ|ate .o f|
|00005c40| 69 6c 65 0a 61 6e 64 20 | 6c 6f 61 64 65 64 20 6c |ile.and |loaded l|
|00005c50| 69 6b 65 20 5c 76 65 72 | 62 7c 28 6c 6f 61 64 20 |ike \ver|b|(load |
|00005c60| 22 66 69 6c 65 2e 6f 22 | 29 7c 2e 0a 54 68 65 20 |"file.o"|)|..The |
|00005c70| 45 6c 6b 20 64 79 6e 61 | 6d 69 63 20 6c 6f 61 64 |Elk dyna|mic load|
|00005c80| 65 72 20 63 61 6c 6c 73 | 20 61 6e 79 20 72 6f 75 |er calls| any rou|
|00005c90| 74 69 6e 65 73 20 69 6e | 20 66 69 6c 65 2e 6f 20 |tines in| file.o |
|00005ca0| 77 68 69 63 68 20 62 65 | 67 69 6e 20 77 69 74 68 |which be|gin with|
|00005cb0| 0a 5c 62 65 67 69 6e 7b | 76 65 72 62 61 74 69 6d |.\begin{|verbatim|
|00005cc0| 7d 0a 20 20 20 20 69 6e | 69 74 5f 2e 2e 2e 0a 5c |}. in|it_....\|
|00005cd0| 65 6e 64 7b 76 65 72 62 | 61 74 69 6d 7d 0a 73 6f |end{verb|atim}.so|
|00005ce0| 20 74 68 65 20 66 69 6c | 65 27 73 20 69 6e 69 74 | the fil|e's init|
|00005cf0| 69 61 6c 69 7a 61 74 69 | 6f 6e 20 72 6f 75 74 69 |ializati|on routi|
|00005d00| 6e 65 20 77 69 6c 6c 20 | 62 65 20 61 75 74 6f 6d |ne will |be autom|
|00005d10| 61 74 69 63 61 6c 6c 79 | 20 63 61 6c 6c 65 64 0a |atically| called.|
|00005d20| 69 66 20 69 74 20 69 73 | 20 6e 61 6d 65 64 20 7b |if it is| named {|
|00005d30| 5c 74 74 20 69 6e 69 74 | 2d 75 6e 64 65 72 62 61 |\tt init|-underba|
|00005d40| 72 2d 73 6f 6d 65 74 68 | 69 6e 67 7d 2e 0a 0a 55 |r-someth|ing}...U|
|00005d50| 6e 66 6f 72 74 75 6e 61 | 74 65 6c 79 20 61 20 66 |nfortuna|tely a f|
|00005d60| 69 6c 65 20 63 6f 6e 74 | 61 69 6e 69 6e 67 20 73 |ile cont|aining s|
|00005d70| 75 63 68 20 61 6e 20 69 | 6e 69 74 69 61 6c 69 7a |uch an i|nitializ|
|00005d80| 61 74 69 6f 6e 20 72 6f | 75 74 69 6e 65 20 63 61 |ation ro|utine ca|
|00005d90| 6e 6e 6f 74 20 74 68 65 | 6e 20 62 65 0a 6c 69 6e |nnot the|n be.lin|
|00005da0| 6b 65 64 20 77 69 74 68 | 20 61 6e 20 6f 72 64 69 |ked with| an ordi|
|00005db0| 6e 61 72 79 20 43 20 70 | 72 6f 67 72 61 6d 2c 20 |nary C p|rogram, |
|00005dc0| 62 65 63 61 75 73 65 20 | 74 68 65 20 69 6e 69 74 |because |the init|
|00005dd0| 69 61 6c 69 7a 61 74 69 | 6f 6e 20 63 61 6c 6c 73 |ializati|on calls|
|00005de0| 20 0a 5c 62 65 67 69 6e | 7b 76 65 72 62 61 74 69 | .\begin|{verbati|
|00005df0| 6d 7d 0a 20 20 20 20 44 | 65 66 69 6e 65 5f 46 6f |m}. D|efine_Fo|
|00005e00| 72 65 69 67 6e 28 29 20 | 2f 20 44 65 66 69 6e 65 |reign() |/ Define|
|00005e10| 5f 46 6f 72 74 61 62 28 | 29 0a 5c 65 6e 64 7b 76 |_Fortab(|).\end{v|
|00005e20| 65 72 62 61 74 69 6d 7d | 0a 77 69 6c 6c 20 72 65 |erbatim}|.will re|
|00005e30| 73 75 6c 74 20 69 6e 20 | 75 6e 64 65 66 69 6e 65 |sult in |undefine|
|00005e40| 64 20 72 65 66 65 72 65 | 6e 63 65 73 2e 0a 0a 54 |d refere|nces...T|
|00005e50| 68 65 20 60 66 6f 72 65 | 69 67 6e 20 6c 69 62 72 |he `fore|ign libr|
|00005e60| 61 72 79 27 20 61 70 70 | 72 6f 61 63 68 20 61 6c |ary' app|roach al|
|00005e70| 6c 6f 77 73 20 63 6f 64 | 65 20 74 6f 20 62 65 20 |lows cod|e to be |
|00005e80| 77 72 69 74 74 65 6e 20 | 73 6f 20 74 68 61 74 20 |written |so that |
|00005e90| 69 74 20 63 61 6e 20 62 | 65 20 0a 6c 69 6e 6b 65 |it can b|e .linke|
|00005ea0| 64 20 69 6e 20 62 6f 74 | 68 20 6f 72 64 69 6e 61 |d in bot|h ordina|
|00005eb0| 72 79 20 43 20 70 72 6f | 67 72 61 6d 73 20 61 6e |ry C pro|grams an|
|00005ec0| 64 20 69 6e 20 45 6c 6b | 2e 0a 55 73 65 20 74 68 |d in Elk|..Use th|
|00005ed0| 65 20 66 6f 6c 6c 6f 77 | 69 6e 67 20 74 65 6d 70 |e follow|ing temp|
|00005ee0| 6c 61 74 65 20 69 6e 20 | 77 72 69 74 69 6e 67 20 |late in |writing |
|00005ef0| 73 75 63 68 20 61 20 66 | 69 6c 65 3a 0a 5c 62 65 |such a f|ile:.\be|
|00005f00| 67 69 6e 7b 76 65 72 62 | 61 74 69 6d 7d 0a 20 20 |gin{verb|atim}. |
|00005f10| 20 20 20 20 20 20 23 69 | 6e 63 6c 75 64 65 20 3c | #i|nclude <|
|00005f20| 72 74 6c 70 6b 67 2e 68 | 3e 20 20 2f 2a 20 64 6f |rtlpkg.h|> /* do|
|00005f30| 20 6e 6f 74 20 69 6e 63 | 6c 75 64 65 20 7a 65 6c | not inc|lude zel|
|00005f40| 6b 2e 68 20 2a 2f 0a 20 | 20 20 20 20 20 20 20 0a |k.h */. | .|
|00005f50| 20 20 20 20 20 20 20 20 | 2f 2a 20 70 72 65 66 61 | |/* prefa|
|00005f60| 63 65 20 65 61 63 68 20 | 72 6f 75 74 69 6e 65 20 |ce each |routine |
|00005f70| 77 69 74 68 20 61 20 66 | 6f 72 65 69 67 6e 20 6c |with a f|oreign l|
|00005f80| 69 6e 6b 20 64 65 66 69 | 6e 65 20 2a 2f 0a 20 20 |ink defi|ne */. |
|00005f90| 20 20 20 20 20 20 23 64 | 65 66 69 6e 65 20 4c 49 | #d|efine LI|
|00005fa0| 4e 4b 5f 6d 79 73 75 62 | 20 7b 20 22 6d 79 73 75 |NK_mysub| { "mysu|
|00005fb0| 62 22 2c 20 6d 79 73 75 | 62 2c 20 22 53 22 20 7d |b", mysu|b, "S" }|
|00005fc0| 20 2c 0a 20 20 20 20 20 | 20 20 20 0a 20 20 20 20 | ,. | . |
|00005fd0| 20 20 20 20 2f 2a 20 61 | 20 73 61 6d 70 6c 65 20 | /* a| sample |
|00005fe0| 72 6f 75 74 69 6e 65 20 | 2a 2f 0a 20 20 20 20 20 |routine |*/. |
|00005ff0| 20 20 20 76 6f 69 64 20 | 6d 79 73 75 62 28 63 68 | void |mysub(ch|
|00006000| 61 72 20 2a 73 29 20 7b | 0a 20 20 20 20 20 20 20 |ar *s) {|. |
|00006010| 20 20 20 70 72 69 6e 74 | 66 28 22 63 61 6c 6c 65 | print|f("calle|
|00006020| 64 20 6d 79 73 75 62 20 | 77 69 74 68 20 25 73 5c |d mysub |with %s\|
|00006030| 6e 22 2c 73 29 3b 0a 20 | 20 20 20 20 20 20 20 7d |n",s);. | }|
|00006040| 0a 20 20 20 20 20 20 20 | 20 0a 20 20 20 20 20 20 |. | . |
|00006050| 20 20 2f 2a 20 61 74 20 | 74 68 65 20 65 6e 64 20 | /* at |the end |
|00006060| 6f 66 20 74 68 65 20 66 | 69 6c 65 2c 20 61 20 74 |of the f|ile, a t|
|00006070| 61 62 6c 65 20 6f 66 20 | 61 6c 6c 20 66 6f 72 65 |able of |all fore|
|00006080| 69 67 6e 20 6c 69 6e 6b | 73 20 2a 2f 0a 20 20 20 |ign link|s */. |
|00006090| 20 20 20 20 20 73 74 72 | 75 63 74 20 66 6f 72 64 | str|uct ford|
|000060a0| 65 66 20 66 6f 72 74 61 | 62 20 7b 0a 20 20 20 20 |ef forta|b {. |
|000060b0| 20 20 20 20 20 20 4c 49 | 4e 4b 5f 6d 79 73 75 62 | LI|NK_mysub|
|000060c0| 20 20 20 20 20 20 20 20 | 20 20 20 20 2f 2a 20 67 | | /* g|
|000060d0| 61 74 68 65 72 20 61 6c | 6c 20 74 68 65 20 6c 69 |ather al|l the li|
|000060e0| 6e 6b 20 64 65 66 69 6e | 69 74 69 6f 6e 73 20 2a |nk defin|itions *|
|000060f0| 2f 0a 20 20 20 20 20 20 | 20 20 20 20 30 20 20 20 |/. | 0 |
|00006100| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00006110| 20 20 2f 2a 20 69 6e 64 | 69 63 61 74 65 20 65 6e | /* ind|icate en|
|00006120| 64 20 6f 66 20 74 61 62 | 6c 65 20 2a 2f 0a 20 20 |d of tab|le */. |
|00006130| 20 20 20 20 20 20 7d 3b | 0a 20 20 20 20 20 20 20 | };|. |
|00006140| 20 0a 20 20 20 20 20 20 | 20 20 2f 2a 20 70 61 63 | . | /* pac|
|00006150| 6b 61 67 65 20 73 74 72 | 75 63 74 75 72 65 20 2a |kage str|ucture *|
|00006160| 2f 0a 20 20 20 20 20 20 | 20 20 67 6c 6f 62 61 6c |/. | global|
|00006170| 20 46 4f 52 50 4b 47 30 | 20 70 6b 67 5f 6d 79 66 | FORPKG0| pkg_myf|
|00006180| 69 6c 65 20 3d 20 7b 0a | 20 20 20 20 20 20 20 20 |ile = {.| |
|00006190| 20 20 20 20 30 2c 20 20 | 20 20 20 20 20 20 20 20 | 0, | |
|000061a0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|000061b0| 20 20 20 20 20 20 20 20 | 2f 2a 70 61 63 6b 61 67 | |/*packag|
|000061c0| 65 74 79 70 65 2e 20 30 | 3d 63 75 72 72 65 6e 74 |etype. 0|=current|
|000061d0| 2a 2f 0a 20 20 20 20 20 | 20 20 20 20 20 20 20 28 |*/. | (|
|000061e0| 69 6e 74 20 28 2a 29 28 | 29 29 30 2c 20 20 20 20 |int (*)(|))0, |
|000061f0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00006200| 20 20 20 2f 2a 69 6e 69 | 74 5f 2a 2f 0a 20 20 20 | /*ini|t_*/. |
|00006210| 20 20 20 20 20 20 20 20 | 20 30 2c 20 20 20 20 20 | | 0, |
|00006220| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00006230| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 2f 2a 73 | | /*s|
|00006240| 74 61 62 2c 2a 2f 0a 20 | 20 20 20 20 20 20 20 20 |tab,*/. | |
|00006250| 20 20 20 28 73 74 72 75 | 63 74 20 66 6f 72 64 65 | (stru|ct forde|
|00006260| 66 20 2a 29 66 74 61 62 | 2c 20 20 20 20 20 20 20 |f *)ftab|, |
|00006270| 20 20 20 20 20 20 20 2f | 2a 66 74 61 62 2c 20 70 | /|*ftab, p|
|00006280| 75 74 20 74 68 65 20 74 | 61 62 6c 65 20 68 65 72 |ut the t|able her|
|00006290| 65 2a 2f 0a 20 20 20 20 | 20 20 20 20 20 20 20 20 |e*/. | |
|000062a0| 28 73 74 72 75 63 74 20 | 66 6f 72 64 65 66 5f 75 |(struct |fordef_u|
|000062b0| 73 61 67 65 20 2a 29 30 | 20 20 20 20 20 20 20 20 |sage *)0| |
|000062c0| 20 20 20 20 2f 2a 66 75 | 74 61 62 2c 2a 2f 0a 20 | /*fu|tab,*/. |
|000062d0| 20 20 20 20 20 20 20 7d | 3b 0a 0a 20 20 20 20 20 | }|;.. |
|000062e0| 20 20 20 2f 2a 20 61 20 | 66 75 6e 63 74 69 6f 6e | /* a |function|
|000062f0| 20 6e 61 6d 65 64 20 50 | 4b 47 72 74 6e 5f 58 58 | named P|KGrtn_XX|
|00006300| 20 72 65 74 75 72 6e 73 | 20 0a 20 20 20 20 20 20 | returns| . |
|00006310| 20 20 20 2a 20 74 68 65 | 20 61 64 64 72 65 73 73 | * the| address|
|00006320| 20 70 61 63 6b 61 67 65 | 20 73 74 72 75 63 74 75 | package| structu|
|00006330| 72 65 20 2a 2f 0a 20 20 | 20 20 20 20 20 20 46 4f |re */. | FO|
|00006340| 52 50 4b 47 30 20 2a 50 | 4b 47 72 74 6e 5f 4d 79 |RPKG0 *P|KGrtn_My|
|00006350| 28 29 20 7b 20 72 65 74 | 75 72 6e 20 26 70 6b 67 |() { ret|urn &pkg|
|00006360| 5f 4d 79 3b 20 7d 0a 5c | 65 6e 64 7b 76 65 72 62 |_My; }.\|end{verb|
|00006370| 61 74 69 6d 7d 0a 49 6e | 20 74 68 69 73 20 61 70 |atim}.In| this ap|
|00006380| 70 72 6f 61 63 68 2c 20 | 77 68 65 6e 20 61 20 2e |proach, |when a .|
|00006390| 6f 20 66 69 6c 65 20 69 | 73 20 64 79 6e 61 6d 69 |o file i|s dynami|
|000063a0| 63 61 6c 6c 79 20 6c 6f | 61 64 65 64 2c 0a 61 6e |cally lo|aded,.an|
|000063b0| 79 20 72 6f 75 74 69 6e | 65 73 20 6e 61 6d 65 64 |y routin|es named|
|000063c0| 20 5c 76 65 72 62 7c 50 | 4b 47 72 74 6e 5f 58 58 | \verb|P|KGrtn_XX|
|000063d0| 7c 20 61 72 65 20 63 61 | 6c 6c 65 64 2e 0a 54 68 || are ca|lled..Th|
|000063e0| 65 73 65 20 72 6f 75 74 | 69 6e 65 73 20 73 68 6f |ese rout|ines sho|
|000063f0| 75 6c 64 20 72 65 74 75 | 72 6e 20 61 20 70 6f 69 |uld retu|rn a poi|
+--------+-------------------------+-------------------------+--------+--------+
Only 25.0 KB of data is shown above.